| Alexander Hansen | 40fb549 | 2025-10-28 17:56:12 +0100 | [diff] [blame^] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright 2019 IBM Corporation |
| 3 | |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 4 | #include "manager.hpp" |
| 5 | |
| 6 | #include "additional_data.hpp" |
| Matt Spinler | 3387eac | 2023-07-06 14:56:02 -0500 | [diff] [blame] | 7 | #include "elog_serialize.hpp" |
| Matt Spinler | 05c2c6c | 2019-12-18 14:02:09 -0600 | [diff] [blame] | 8 | #include "json_utils.hpp" |
| Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 9 | #include "pel.hpp" |
| Vijay Lobo | 2fb1021 | 2021-08-22 23:24:16 -0500 | [diff] [blame] | 10 | #include "pel_entry.hpp" |
| Matt Spinler | 8a09b98 | 2025-05-09 14:09:10 -0500 | [diff] [blame] | 11 | #include "pel_values.hpp" |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 12 | #include "service_indicators.hpp" |
| Matt Spinler | 8b81ec0 | 2022-07-12 13:25:37 -0500 | [diff] [blame] | 13 | #include "severity.hpp" |
| Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 14 | |
| Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 15 | #include <sys/inotify.h> |
| Matt Spinler | 6b1a5c8 | 2020-01-07 08:48:53 -0600 | [diff] [blame] | 16 | #include <unistd.h> |
| 17 | |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 18 | #include <phosphor-logging/lg2.hpp> |
| Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 19 | #include <xyz/openbmc_project/Common/error.hpp> |
| 20 | #include <xyz/openbmc_project/Logging/Create/server.hpp> |
| 21 | |
| Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 22 | #include <filesystem> |
| Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 23 | #include <format> |
| Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 24 | #include <fstream> |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 25 | |
| 26 | namespace openpower |
| 27 | { |
| 28 | namespace pels |
| 29 | { |
| 30 | |
| 31 | using namespace phosphor::logging; |
| Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 32 | namespace fs = std::filesystem; |
| Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 33 | namespace rg = openpower::pels::message; |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 34 | |
| Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 35 | namespace common_error = sdbusplus::xyz::openbmc_project::Common::Error; |
| 36 | |
| Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 37 | using Create = sdbusplus::server::xyz::openbmc_project::logging::Create; |
| Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 38 | |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 39 | namespace additional_data |
| 40 | { |
| 41 | constexpr auto rawPEL = "RAWPEL"; |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 42 | constexpr auto esel = "ESEL"; |
| Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 43 | constexpr auto error = "ERROR_NAME"; |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 44 | } // namespace additional_data |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 45 | |
| Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 46 | constexpr auto defaultLogMessage = "xyz.openbmc_project.Logging.Error.Default"; |
| Matt Spinler | 0dd22c8 | 2023-05-04 15:28:12 -0500 | [diff] [blame] | 47 | constexpr uint32_t bmcThermalCompID = 0x2700; |
| 48 | constexpr uint32_t bmcFansCompID = 0x2800; |
| Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 49 | |
| Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 50 | Manager::~Manager() |
| 51 | { |
| 52 | if (_pelFileDeleteFD != -1) |
| 53 | { |
| 54 | if (_pelFileDeleteWatchFD != -1) |
| 55 | { |
| 56 | inotify_rm_watch(_pelFileDeleteFD, _pelFileDeleteWatchFD); |
| 57 | } |
| 58 | close(_pelFileDeleteFD); |
| 59 | } |
| 60 | } |
| 61 | |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 62 | void Manager::create(const std::string& message, uint32_t obmcLogID, |
| 63 | uint64_t timestamp, Entry::Level severity, |
| Patrick Williams | e594063 | 2024-11-22 20:47:58 -0500 | [diff] [blame] | 64 | const std::map<std::string, std::string>& additionalData, |
| Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 65 | const std::vector<std::string>& associations, |
| 66 | const FFDCEntries& ffdc) |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 67 | { |
| 68 | AdditionalData ad{additionalData}; |
| 69 | |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 70 | // If a PEL was passed in via a filename or in an ESEL, |
| 71 | // use that. Otherwise, create one. |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 72 | auto rawPelPath = ad.getValue(additional_data::rawPEL); |
| 73 | if (rawPelPath) |
| 74 | { |
| 75 | addRawPEL(*rawPelPath, obmcLogID); |
| 76 | } |
| 77 | else |
| 78 | { |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 79 | auto esel = ad.getValue(additional_data::esel); |
| 80 | if (esel) |
| 81 | { |
| 82 | addESELPEL(*esel, obmcLogID); |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | createPEL(message, obmcLogID, timestamp, severity, additionalData, |
| Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 87 | associations, ffdc); |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 88 | } |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 89 | } |
| Adriana Kobylak | e7d271a | 2020-12-07 14:32:44 -0600 | [diff] [blame] | 90 | |
| 91 | setEntryPath(obmcLogID); |
| Vijay Lobo | cbc93a4 | 2021-05-20 19:04:07 -0500 | [diff] [blame] | 92 | setServiceProviderNotifyFlag(obmcLogID); |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void Manager::addRawPEL(const std::string& rawPelPath, uint32_t obmcLogID) |
| 96 | { |
| Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 97 | if (fs::exists(rawPelPath)) |
| 98 | { |
| 99 | std::ifstream file(rawPelPath, std::ios::in | std::ios::binary); |
| 100 | |
| 101 | auto data = std::vector<uint8_t>(std::istreambuf_iterator<char>(file), |
| 102 | std::istreambuf_iterator<char>()); |
| 103 | if (file.fail()) |
| 104 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 105 | lg2::error( |
| 106 | "Filesystem error reading a raw PEL. File = {FILE}, obmcLogID = {LOGID}", |
| 107 | "FILE", rawPelPath, "LOGID", obmcLogID); |
| Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 108 | // TODO, Decide what to do here. Maybe nothing. |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | file.close(); |
| 113 | |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 114 | addPEL(data, obmcLogID); |
| Matt Spinler | 6741692 | 2021-07-19 12:34:57 -0600 | [diff] [blame] | 115 | |
| 116 | std::error_code ec; |
| 117 | fs::remove(rawPelPath, ec); |
| Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 118 | } |
| 119 | else |
| 120 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 121 | lg2::error( |
| 122 | "Raw PEL file from BMC event log does not exit. File = {FILE}, obmcLogID = {LOGID}", |
| 123 | "FILE", rawPelPath, "LOGID", obmcLogID); |
| Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 124 | } |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 125 | } |
| 126 | |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 127 | void Manager::addPEL(std::vector<uint8_t>& pelData, uint32_t obmcLogID) |
| 128 | { |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 129 | auto pel = std::make_unique<openpower::pels::PEL>(pelData, obmcLogID); |
| 130 | if (pel->valid()) |
| 131 | { |
| Sumit Kumar | 8ec4156 | 2021-10-29 05:39:37 -0500 | [diff] [blame] | 132 | // PELs created by others still need this field set by us. |
| 133 | pel->setCommitTime(); |
| 134 | |
| Sumit Kumar | a1e4084 | 2021-06-23 09:52:25 -0500 | [diff] [blame] | 135 | // Assign Id other than to Hostbot PEL |
| 136 | if ((pel->privateHeader()).creatorID() != |
| 137 | static_cast<uint8_t>(CreatorID::hostboot)) |
| 138 | { |
| 139 | pel->assignID(); |
| 140 | } |
| Sumit Kumar | 2ccdcef | 2021-07-31 10:04:58 -0500 | [diff] [blame] | 141 | else |
| 142 | { |
| 143 | const Repository::LogID id{Repository::LogID::Pel(pel->id())}; |
| 144 | auto result = _repo.hasPEL(id); |
| 145 | if (result) |
| 146 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 147 | lg2::warning( |
| 148 | "Duplicate HostBoot PEL ID {ID} found, moving it to archive folder", |
| 149 | "ID", lg2::hex, pel->id()); |
| Sumit Kumar | 2ccdcef | 2021-07-31 10:04:58 -0500 | [diff] [blame] | 150 | |
| 151 | _repo.archivePEL(*pel); |
| Matt Spinler | d8fb5ba | 2022-01-25 13:01:14 -0600 | [diff] [blame] | 152 | |
| 153 | // No need to keep around the openBMC event log entry |
| 154 | scheduleObmcLogDelete(obmcLogID); |
| Sumit Kumar | 2ccdcef | 2021-07-31 10:04:58 -0500 | [diff] [blame] | 155 | return; |
| 156 | } |
| 157 | } |
| Sumit Kumar | a1e4084 | 2021-06-23 09:52:25 -0500 | [diff] [blame] | 158 | |
| Sumit Kumar | 3160a54 | 2021-04-26 08:07:04 -0500 | [diff] [blame] | 159 | // Update System Info to Extended User Data |
| 160 | pel->updateSysInfoInExtendedUserDataSection(*_dataIface); |
| 161 | |
| Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 162 | // Check for severity 0x51 and update boot progress SRC |
| 163 | updateProgressSRC(pel); |
| 164 | |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 165 | try |
| 166 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 167 | lg2::debug("Adding external PEL {ID} (BMC ID {BMCID}) to repo", |
| 168 | "ID", lg2::hex, pel->id(), "BMCID", obmcLogID); |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 169 | _repo.add(pel); |
| Matt Spinler | 7e727a3 | 2020-07-07 15:00:17 -0500 | [diff] [blame] | 170 | |
| 171 | if (_repo.sizeWarning()) |
| 172 | { |
| 173 | scheduleRepoPrune(); |
| 174 | } |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 175 | |
| 176 | // Activate any resulting service indicators if necessary |
| 177 | auto policy = service_indicators::getPolicy(*_dataIface); |
| 178 | policy->activate(*pel); |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 179 | } |
| Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 180 | catch (const std::exception& e) |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 181 | { |
| 182 | // Probably a full or r/o filesystem, not much we can do. |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 183 | lg2::error("Unable to add PEL {ID} to Repository", "ID", lg2::hex, |
| 184 | pel->id()); |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 185 | } |
| Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 186 | |
| Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 187 | updateEventId(pel); |
| Matt Spinler | 28d6ae2 | 2022-03-18 11:18:27 -0500 | [diff] [blame] | 188 | updateResolution(*pel); |
| Matt Spinler | 3387eac | 2023-07-06 14:56:02 -0500 | [diff] [blame] | 189 | serializeLogEntry(obmcLogID); |
| Vijay Lobo | afb1b46 | 2021-07-21 23:29:13 -0500 | [diff] [blame] | 190 | createPELEntry(obmcLogID); |
| Matt Spinler | df5cb83 | 2022-07-12 12:47:26 -0500 | [diff] [blame] | 191 | |
| 192 | // Check if firmware should quiesce system due to error |
| 193 | checkPelAndQuiesce(pel); |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 194 | } |
| 195 | else |
| 196 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 197 | lg2::error("Invalid PEL received from the host. BMC ID = {ID}", "ID", |
| 198 | obmcLogID); |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 199 | |
| 200 | AdditionalData ad; |
| 201 | ad.add("PLID", getNumberString("0x%08X", pel->plid())); |
| 202 | ad.add("OBMC_LOG_ID", std::to_string(obmcLogID)); |
| 203 | ad.add("PEL_SIZE", std::to_string(pelData.size())); |
| 204 | |
| 205 | std::string asciiString; |
| 206 | auto src = pel->primarySRC(); |
| 207 | if (src) |
| 208 | { |
| 209 | asciiString = (*src)->asciiString(); |
| 210 | } |
| 211 | |
| 212 | ad.add("SRC", asciiString); |
| 213 | |
| 214 | _eventLogger.log("org.open_power.Logging.Error.BadHostPEL", |
| 215 | Entry::Level::Error, ad); |
| Matt Spinler | fe72189 | 2020-04-02 10:28:08 -0500 | [diff] [blame] | 216 | |
| 217 | // Save it to a file for debug in the lab. Just keep the latest. |
| 218 | // Not adding it to the PEL because it could already be max size |
| 219 | // and don't want to truncate an already invalid PEL. |
| 220 | std::ofstream pelFile{getPELRepoPath() / "badPEL"}; |
| 221 | pelFile.write(reinterpret_cast<const char*>(pelData.data()), |
| 222 | pelData.size()); |
| Matt Spinler | d8fb5ba | 2022-01-25 13:01:14 -0600 | [diff] [blame] | 223 | |
| 224 | // No need to keep around the openBMC event log entry |
| 225 | scheduleObmcLogDelete(obmcLogID); |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
| 229 | void Manager::addESELPEL(const std::string& esel, uint32_t obmcLogID) |
| 230 | { |
| 231 | std::vector<uint8_t> data; |
| 232 | |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 233 | lg2::debug("Adding PEL from ESEL. BMC ID = {ID}", "ID", obmcLogID); |
| Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 234 | |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 235 | try |
| 236 | { |
| Matt Spinler | f904caf | 2025-05-09 11:46:45 -0500 | [diff] [blame] | 237 | data = eselToRawData(esel); |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 238 | } |
| Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 239 | catch (const std::exception& e) |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 240 | { |
| 241 | // Try to add it below anyway, so it follows the usual bad data path. |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 242 | lg2::error("Problems converting ESEL string to a byte vector"); |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | addPEL(data, obmcLogID); |
| 246 | } |
| 247 | |
| 248 | std::vector<uint8_t> Manager::eselToRawData(const std::string& esel) |
| 249 | { |
| 250 | std::vector<uint8_t> data; |
| 251 | std::string byteString; |
| 252 | |
| 253 | // As the eSEL string looks like: "50 48 00 ab ..." there are 3 |
| 254 | // characters per raw byte, and since the actual PEL data starts |
| 255 | // at the 16th byte, the code will grab the PEL data starting at |
| 256 | // offset 48 in the string. |
| 257 | static constexpr size_t pelStart = 16 * 3; |
| 258 | |
| 259 | if (esel.size() <= pelStart) |
| 260 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 261 | lg2::error("ESEL data too short, length = {LEN}", "LEN", esel.size()); |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 262 | throw std::length_error("ESEL data too short"); |
| 263 | } |
| 264 | |
| 265 | for (size_t i = pelStart; i < esel.size(); i += 3) |
| 266 | { |
| 267 | if (i + 1 < esel.size()) |
| 268 | { |
| 269 | byteString = esel.substr(i, 2); |
| 270 | data.push_back(std::stoi(byteString, nullptr, 16)); |
| 271 | } |
| 272 | else |
| 273 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 274 | lg2::error("ESEL data too short, length = {LEN}", "LEN", |
| 275 | esel.size()); |
| Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 276 | throw std::length_error("ESEL data too short"); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | return data; |
| 281 | } |
| 282 | |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 283 | void Manager::erase(uint32_t obmcLogID) |
| 284 | { |
| Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 285 | Repository::LogID id{Repository::LogID::Obmc(obmcLogID)}; |
| 286 | |
| Vijay Lobo | afb1b46 | 2021-07-21 23:29:13 -0500 | [diff] [blame] | 287 | auto path = std::string(OBJ_ENTRY) + '/' + std::to_string(obmcLogID); |
| 288 | _pelEntries.erase(path); |
| Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 289 | _repo.remove(id); |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 290 | } |
| 291 | |
| harsh-agarwal1 | d763db3 | 2024-09-03 09:18:50 -0500 | [diff] [blame] | 292 | void Manager::getLogIDWithHwIsolation(std::vector<uint32_t>& idsWithHwIsoEntry) |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 293 | { |
| harsh-agarwal1 | d763db3 | 2024-09-03 09:18:50 -0500 | [diff] [blame] | 294 | idsWithHwIsoEntry = _dataIface->getLogIDWithHwIsolation(); |
| 295 | } |
| 296 | |
| 297 | bool Manager::isDeleteProhibited(uint32_t obmcLogID) |
| 298 | { |
| harsh-agarwal1 | 760b981 | 2025-03-18 23:23:24 -0500 | [diff] [blame] | 299 | Repository::LogID id{Repository::LogID::Obmc(obmcLogID)}; |
| 300 | if (!_repo.hasPEL(id)) |
| 301 | { |
| 302 | return false; |
| 303 | } |
| harsh-agarwal1 | d763db3 | 2024-09-03 09:18:50 -0500 | [diff] [blame] | 304 | auto entryPath{std::string(OBJ_ENTRY) + '/' + std::to_string(obmcLogID)}; |
| 305 | auto entry = _pelEntries.find(entryPath); |
| 306 | if (entry != _pelEntries.end()) |
| 307 | { |
| 308 | if (entry->second->guard()) |
| 309 | { |
| 310 | auto hwIsolationAssocPaths = _dataIface->getAssociatedPaths( |
| 311 | entryPath += "/isolated_hw_entry", "/", 0, |
| 312 | {"xyz.openbmc_project.HardwareIsolation.Entry"}); |
| 313 | if (!hwIsolationAssocPaths.empty()) |
| 314 | { |
| 315 | return true; |
| 316 | } |
| 317 | } |
| 318 | } |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 319 | return false; |
| 320 | } |
| 321 | |
| Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 322 | PelFFDC Manager::convertToPelFFDC(const FFDCEntries& ffdc) |
| 323 | { |
| 324 | PelFFDC pelFFDC; |
| 325 | |
| 326 | std::for_each(ffdc.begin(), ffdc.end(), [&pelFFDC](const auto& f) { |
| 327 | PelFFDCfile pf; |
| 328 | pf.subType = std::get<ffdcSubtypePos>(f); |
| 329 | pf.version = std::get<ffdcVersionPos>(f); |
| 330 | pf.fd = std::get<ffdcFDPos>(f); |
| 331 | |
| 332 | switch (std::get<ffdcFormatPos>(f)) |
| 333 | { |
| 334 | case Create::FFDCFormat::JSON: |
| 335 | pf.format = UserDataFormat::json; |
| 336 | break; |
| 337 | case Create::FFDCFormat::CBOR: |
| 338 | pf.format = UserDataFormat::cbor; |
| 339 | break; |
| 340 | case Create::FFDCFormat::Text: |
| 341 | pf.format = UserDataFormat::text; |
| 342 | break; |
| 343 | case Create::FFDCFormat::Custom: |
| 344 | pf.format = UserDataFormat::custom; |
| 345 | break; |
| 346 | } |
| 347 | |
| 348 | pelFFDC.push_back(pf); |
| 349 | }); |
| 350 | |
| 351 | return pelFFDC; |
| 352 | } |
| 353 | |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 354 | void Manager::createPEL( |
| 355 | const std::string& message, uint32_t obmcLogID, uint64_t timestamp, |
| 356 | phosphor::logging::Entry::Level severity, |
| Patrick Williams | e594063 | 2024-11-22 20:47:58 -0500 | [diff] [blame] | 357 | const std::map<std::string, std::string>& additionalData, |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 358 | const std::vector<std::string>& /*associations*/, const FFDCEntries& ffdc) |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 359 | { |
| Matt Spinler | 085efbb | 2025-07-18 12:54:39 -0500 | [diff] [blame] | 360 | auto start = std::chrono::steady_clock::now(); |
| Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 361 | auto entry = _registry.lookup(message, rg::LookupType::name); |
| Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 362 | auto pelFFDC = convertToPelFFDC(ffdc); |
| 363 | AdditionalData ad{additionalData}; |
| Matt Spinler | 1d4c74a | 2019-12-16 14:40:21 -0600 | [diff] [blame] | 364 | std::string msg; |
| Matt Spinler | 67456c2 | 2019-10-21 12:22:49 -0500 | [diff] [blame] | 365 | |
| Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 366 | if (!entry) |
| Matt Spinler | 67456c2 | 2019-10-21 12:22:49 -0500 | [diff] [blame] | 367 | { |
| Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 368 | // Instead, get the default entry that means there is no |
| 369 | // other matching entry. This error will still use the |
| 370 | // AdditionalData values of the original error, and this |
| 371 | // code will add the error message value that wasn't found |
| 372 | // to this AD. This way, there will at least be a PEL, |
| 373 | // possibly with callouts, to allow users to debug the |
| 374 | // issue that caused the error even without its own PEL. |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 375 | lg2::error("Event not found in PEL message registry: {MSG}", "MSG", |
| 376 | message); |
| Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 377 | |
| 378 | entry = _registry.lookup(defaultLogMessage, rg::LookupType::name); |
| 379 | if (!entry) |
| 380 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 381 | lg2::error("Default event not found in PEL message registry"); |
| Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 382 | return; |
| 383 | } |
| 384 | |
| 385 | ad.add(additional_data::error, message); |
| 386 | } |
| 387 | |
| 388 | auto pel = std::make_unique<openpower::pels::PEL>( |
| Matt Spinler | 9d92109 | 2022-12-15 11:54:49 -0600 | [diff] [blame] | 389 | *entry, obmcLogID, timestamp, severity, ad, pelFFDC, *_dataIface, |
| 390 | *_journal); |
| Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 391 | |
| 392 | _repo.add(pel); |
| 393 | |
| 394 | if (_repo.sizeWarning()) |
| 395 | { |
| 396 | scheduleRepoPrune(); |
| 397 | } |
| 398 | |
| Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 399 | // Check for severity 0x51 and update boot progress SRC |
| 400 | updateProgressSRC(pel); |
| 401 | |
| Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 402 | // Activate any resulting service indicators if necessary |
| 403 | auto policy = service_indicators::getPolicy(*_dataIface); |
| 404 | policy->activate(*pel); |
| Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 405 | |
| Matt Spinler | 8b81ec0 | 2022-07-12 13:25:37 -0500 | [diff] [blame] | 406 | updateDBusSeverity(*pel); |
| Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 407 | updateEventId(pel); |
| Matt Spinler | 28d6ae2 | 2022-03-18 11:18:27 -0500 | [diff] [blame] | 408 | updateResolution(*pel); |
| Matt Spinler | 3387eac | 2023-07-06 14:56:02 -0500 | [diff] [blame] | 409 | serializeLogEntry(obmcLogID); |
| Vijay Lobo | afb1b46 | 2021-07-21 23:29:13 -0500 | [diff] [blame] | 410 | createPELEntry(obmcLogID); |
| Matt Spinler | df5cb83 | 2022-07-12 12:47:26 -0500 | [diff] [blame] | 411 | |
| Matt Spinler | 085efbb | 2025-07-18 12:54:39 -0500 | [diff] [blame] | 412 | auto src = pel->primarySRC(); |
| 413 | if (src) |
| 414 | { |
| 415 | auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( |
| 416 | std::chrono::steady_clock::now() - start); |
| 417 | |
| 418 | auto asciiString = (*src)->asciiString(); |
| 419 | while (asciiString.back() == ' ') |
| 420 | { |
| 421 | asciiString.pop_back(); |
| 422 | } |
| 423 | lg2::info("Created PEL {ID} (BMC ID {BMCID}) with SRC {SRC}", "ID", |
| 424 | lg2::hex, pel->id(), "BMCID", pel->obmcLogID(), "SRC", |
| 425 | asciiString, "PEL_CREATE_DURATION", duration.count()); |
| 426 | } |
| 427 | |
| Matt Spinler | df5cb83 | 2022-07-12 12:47:26 -0500 | [diff] [blame] | 428 | // Check if firmware should quiesce system due to error |
| 429 | checkPelAndQuiesce(pel); |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 430 | } |
| 431 | |
| Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 432 | sdbusplus::message::unix_fd Manager::getPEL(uint32_t pelID) |
| 433 | { |
| 434 | Repository::LogID id{Repository::LogID::Pel(pelID)}; |
| 435 | std::optional<int> fd; |
| 436 | |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 437 | lg2::debug("getPEL {ID}", "ID", lg2::hex, pelID); |
| Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 438 | |
| Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 439 | try |
| 440 | { |
| 441 | fd = _repo.getPELFD(id); |
| 442 | } |
| Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 443 | catch (const std::exception& e) |
| Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 444 | { |
| 445 | throw common_error::InternalFailure(); |
| 446 | } |
| 447 | |
| 448 | if (!fd) |
| 449 | { |
| 450 | throw common_error::InvalidArgument(); |
| 451 | } |
| 452 | |
| Matt Spinler | 6b1a5c8 | 2020-01-07 08:48:53 -0600 | [diff] [blame] | 453 | scheduleFDClose(*fd); |
| 454 | |
| Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 455 | return *fd; |
| 456 | } |
| 457 | |
| Matt Spinler | 6b1a5c8 | 2020-01-07 08:48:53 -0600 | [diff] [blame] | 458 | void Manager::scheduleFDClose(int fd) |
| 459 | { |
| 460 | _fdCloserEventSource = std::make_unique<sdeventplus::source::Defer>( |
| Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 461 | _event, std::bind(std::mem_fn(&Manager::closeFD), this, fd, |
| 462 | std::placeholders::_1)); |
| Matt Spinler | 6b1a5c8 | 2020-01-07 08:48:53 -0600 | [diff] [blame] | 463 | } |
| 464 | |
| Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 465 | void Manager::closeFD(int fd, sdeventplus::source::EventBase& /*source*/) |
| Matt Spinler | 6b1a5c8 | 2020-01-07 08:48:53 -0600 | [diff] [blame] | 466 | { |
| 467 | close(fd); |
| 468 | _fdCloserEventSource.reset(); |
| 469 | } |
| 470 | |
| Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 471 | std::vector<uint8_t> Manager::getPELFromOBMCID(uint32_t obmcLogID) |
| 472 | { |
| 473 | Repository::LogID id{Repository::LogID::Obmc(obmcLogID)}; |
| 474 | std::optional<std::vector<uint8_t>> data; |
| 475 | |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 476 | lg2::debug("getPELFromOBMCID {BMCID}", "BMCID", obmcLogID); |
| Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 477 | |
| Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 478 | try |
| 479 | { |
| 480 | data = _repo.getPELData(id); |
| 481 | } |
| Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 482 | catch (const std::exception& e) |
| Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 483 | { |
| 484 | throw common_error::InternalFailure(); |
| 485 | } |
| 486 | |
| 487 | if (!data) |
| 488 | { |
| 489 | throw common_error::InvalidArgument(); |
| 490 | } |
| 491 | |
| 492 | return *data; |
| 493 | } |
| 494 | |
| 495 | void Manager::hostAck(uint32_t pelID) |
| 496 | { |
| 497 | Repository::LogID id{Repository::LogID::Pel(pelID)}; |
| 498 | |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 499 | lg2::debug("HostHack {ID}", "ID", lg2::hex, pelID); |
| Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 500 | |
| Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 501 | if (!_repo.hasPEL(id)) |
| 502 | { |
| 503 | throw common_error::InvalidArgument(); |
| 504 | } |
| 505 | |
| 506 | if (_hostNotifier) |
| 507 | { |
| 508 | _hostNotifier->ackPEL(pelID); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | void Manager::hostReject(uint32_t pelID, RejectionReason reason) |
| 513 | { |
| 514 | Repository::LogID id{Repository::LogID::Pel(pelID)}; |
| 515 | |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 516 | lg2::debug("HostReject {ID}, reason = {REASON}", "ID", lg2::hex, pelID, |
| 517 | "REASON", reason); |
| Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 518 | |
| Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 519 | if (!_repo.hasPEL(id)) |
| 520 | { |
| 521 | throw common_error::InvalidArgument(); |
| 522 | } |
| 523 | |
| Matt Spinler | 05c2c6c | 2019-12-18 14:02:09 -0600 | [diff] [blame] | 524 | if (reason == RejectionReason::BadPEL) |
| Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 525 | { |
| Matt Spinler | 05c2c6c | 2019-12-18 14:02:09 -0600 | [diff] [blame] | 526 | AdditionalData data; |
| 527 | data.add("BAD_ID", getNumberString("0x%08X", pelID)); |
| 528 | _eventLogger.log("org.open_power.Logging.Error.SentBadPELToHost", |
| 529 | Entry::Level::Informational, data); |
| 530 | if (_hostNotifier) |
| Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 531 | { |
| 532 | _hostNotifier->setBadPEL(pelID); |
| 533 | } |
| Matt Spinler | 05c2c6c | 2019-12-18 14:02:09 -0600 | [diff] [blame] | 534 | } |
| 535 | else if ((reason == RejectionReason::HostFull) && _hostNotifier) |
| 536 | { |
| 537 | _hostNotifier->setHostFull(pelID); |
| Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | |
| Matt Spinler | 7e727a3 | 2020-07-07 15:00:17 -0500 | [diff] [blame] | 541 | void Manager::scheduleRepoPrune() |
| 542 | { |
| Matt Spinler | 7e727a3 | 2020-07-07 15:00:17 -0500 | [diff] [blame] | 543 | _repoPrunerEventSource = std::make_unique<sdeventplus::source::Defer>( |
| Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 544 | _event, std::bind(std::mem_fn(&Manager::pruneRepo), this, |
| 545 | std::placeholders::_1)); |
| Matt Spinler | 7e727a3 | 2020-07-07 15:00:17 -0500 | [diff] [blame] | 546 | } |
| 547 | |
| Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 548 | void Manager::pruneRepo(sdeventplus::source::EventBase& /*source*/) |
| Matt Spinler | 7e727a3 | 2020-07-07 15:00:17 -0500 | [diff] [blame] | 549 | { |
| Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 550 | auto idsWithHwIsoEntry = _dataIface->getLogIDWithHwIsolation(); |
| 551 | |
| 552 | auto idsToDelete = _repo.prune(idsWithHwIsoEntry); |
| Matt Spinler | 7e727a3 | 2020-07-07 15:00:17 -0500 | [diff] [blame] | 553 | |
| 554 | // Remove the OpenBMC event logs for the PELs that were just removed. |
| 555 | std::for_each(idsToDelete.begin(), idsToDelete.end(), |
| 556 | [this](auto id) { this->_logManager.erase(id); }); |
| 557 | |
| 558 | _repoPrunerEventSource.reset(); |
| 559 | } |
| 560 | |
| Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 561 | void Manager::setupPELDeleteWatch() |
| 562 | { |
| 563 | _pelFileDeleteFD = inotify_init1(IN_NONBLOCK); |
| 564 | if (-1 == _pelFileDeleteFD) |
| 565 | { |
| 566 | auto e = errno; |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 567 | lg2::error("inotify_init1 failed with errno {ERRNO}", "ERRNO", e); |
| Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 568 | abort(); |
| 569 | } |
| 570 | |
| 571 | _pelFileDeleteWatchFD = inotify_add_watch( |
| 572 | _pelFileDeleteFD, _repo.repoPath().c_str(), IN_DELETE); |
| 573 | if (-1 == _pelFileDeleteWatchFD) |
| 574 | { |
| 575 | auto e = errno; |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 576 | lg2::error("inotify_add_watch failed with errno {ERRNO}", "ERRNO", e); |
| Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 577 | abort(); |
| 578 | } |
| 579 | |
| 580 | _pelFileDeleteEventSource = std::make_unique<sdeventplus::source::IO>( |
| 581 | _event, _pelFileDeleteFD, EPOLLIN, |
| 582 | std::bind(std::mem_fn(&Manager::pelFileDeleted), this, |
| 583 | std::placeholders::_1, std::placeholders::_2, |
| 584 | std::placeholders::_3)); |
| 585 | } |
| 586 | |
| Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 587 | void Manager::pelFileDeleted(sdeventplus::source::IO& /*io*/, int /*fd*/, |
| Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 588 | uint32_t revents) |
| 589 | { |
| 590 | if (!(revents & EPOLLIN)) |
| 591 | { |
| 592 | return; |
| 593 | } |
| 594 | |
| 595 | // An event for 1 PEL uses 48B. When all PELs are deleted at once, |
| 596 | // as many events as there is room for can be handled in one callback. |
| 597 | // A size of 2000 will allow 41 to be processed, with additional |
| 598 | // callbacks being needed to process the remaining ones. |
| Matt Spinler | 9d59d58 | 2021-05-19 07:57:10 -0600 | [diff] [blame] | 599 | std::array<uint8_t, 2000> data{}; |
| Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 600 | auto bytesRead = read(_pelFileDeleteFD, data.data(), data.size()); |
| 601 | if (bytesRead < 0) |
| 602 | { |
| 603 | auto e = errno; |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 604 | lg2::error("Failed reading data from inotify event, errno = {ERRNO}", |
| 605 | "ERRNO", e); |
| Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 606 | abort(); |
| 607 | } |
| 608 | |
| 609 | auto offset = 0; |
| 610 | while (offset < bytesRead) |
| 611 | { |
| 612 | auto event = reinterpret_cast<inotify_event*>(&data[offset]); |
| 613 | if (event->mask & IN_DELETE) |
| 614 | { |
| 615 | std::string filename{event->name}; |
| 616 | |
| 617 | // Get the PEL ID from the filename and tell the |
| 618 | // repo it's been removed, and then delete the BMC |
| 619 | // event log if it's there. |
| 620 | auto pos = filename.find_first_of('_'); |
| 621 | if (pos != std::string::npos) |
| 622 | { |
| 623 | try |
| 624 | { |
| 625 | auto idString = filename.substr(pos + 1); |
| 626 | auto pelID = std::stoul(idString, nullptr, 16); |
| 627 | |
| 628 | Repository::LogID id{Repository::LogID::Pel(pelID)}; |
| 629 | auto removedLogID = _repo.remove(id); |
| 630 | if (removedLogID) |
| 631 | { |
| 632 | _logManager.erase(removedLogID->obmcID.id); |
| 633 | } |
| 634 | } |
| 635 | catch (const std::exception& e) |
| 636 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 637 | lg2::info("Could not find PEL ID from its filename {NAME}", |
| 638 | "NAME", filename); |
| Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | offset += offsetof(inotify_event, name) + event->len; |
| 644 | } |
| 645 | } |
| Matt Spinler | 9cc3007 | 2020-09-16 15:39:34 -0500 | [diff] [blame] | 646 | |
| 647 | std::tuple<uint32_t, uint32_t> Manager::createPELWithFFDCFiles( |
| 648 | std::string message, Entry::Level severity, |
| 649 | std::map<std::string, std::string> additionalData, |
| 650 | std::vector<std::tuple< |
| Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 651 | sdbusplus::server::xyz::openbmc_project::logging::Create::FFDCFormat, |
| Matt Spinler | 9cc3007 | 2020-09-16 15:39:34 -0500 | [diff] [blame] | 652 | uint8_t, uint8_t, sdbusplus::message::unix_fd>> |
| 653 | fFDC) |
| 654 | { |
| Paul Fertser | 221b79b | 2024-03-04 15:40:23 +0000 | [diff] [blame] | 655 | _logManager.create(message, severity, additionalData, fFDC); |
| Matt Spinler | 44893cc | 2020-08-26 11:34:17 -0500 | [diff] [blame] | 656 | |
| 657 | return {_logManager.lastEntryID(), _repo.lastPelID()}; |
| Matt Spinler | 9cc3007 | 2020-09-16 15:39:34 -0500 | [diff] [blame] | 658 | } |
| 659 | |
| Matt Spinler | 8bd4ca4 | 2022-04-01 16:06:06 -0500 | [diff] [blame] | 660 | std::string Manager::getPELJSON(uint32_t obmcLogID) |
| Matt Spinler | aa85a07 | 2022-03-23 11:26:41 -0500 | [diff] [blame] | 661 | { |
| Matt Spinler | 8bd4ca4 | 2022-04-01 16:06:06 -0500 | [diff] [blame] | 662 | // Throws InvalidArgument if not found |
| 663 | auto pelID = getPELIdFromBMCLogId(obmcLogID); |
| 664 | |
| Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 665 | auto cmd = std::format("/usr/bin/peltool -i {:#x}", pelID); |
| Matt Spinler | 8bd4ca4 | 2022-04-01 16:06:06 -0500 | [diff] [blame] | 666 | |
| 667 | FILE* pipe = popen(cmd.c_str(), "r"); |
| 668 | if (!pipe) |
| 669 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 670 | lg2::error("Error running cmd: {CMD}", "CMD", cmd); |
| Matt Spinler | 8bd4ca4 | 2022-04-01 16:06:06 -0500 | [diff] [blame] | 671 | throw common_error::InternalFailure(); |
| 672 | } |
| 673 | |
| 674 | std::string output; |
| 675 | std::array<char, 1024> buffer; |
| 676 | while (fgets(buffer.data(), buffer.size(), pipe) != nullptr) |
| 677 | { |
| 678 | output.append(buffer.data()); |
| 679 | } |
| 680 | |
| 681 | int rc = pclose(pipe); |
| 682 | if (WEXITSTATUS(rc) != 0) |
| 683 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 684 | lg2::error("Error running cmd: {CMD}, rc = {RC}", "CMD", cmd, "RC", rc); |
| Matt Spinler | 8bd4ca4 | 2022-04-01 16:06:06 -0500 | [diff] [blame] | 685 | throw common_error::InternalFailure(); |
| 686 | } |
| 687 | |
| 688 | return output; |
| Matt Spinler | aa85a07 | 2022-03-23 11:26:41 -0500 | [diff] [blame] | 689 | } |
| 690 | |
| Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 691 | void Manager::checkPelAndQuiesce(std::unique_ptr<openpower::pels::PEL>& pel) |
| 692 | { |
| Matt Spinler | b2abc04 | 2021-05-17 15:32:50 -0600 | [diff] [blame] | 693 | if ((pel->userHeader().severity() == |
| 694 | static_cast<uint8_t>(SeverityType::nonError)) || |
| 695 | (pel->userHeader().severity() == |
| 696 | static_cast<uint8_t>(SeverityType::recovered))) |
| Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 697 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 698 | lg2::debug( |
| Matt Spinler | b2abc04 | 2021-05-17 15:32:50 -0600 | [diff] [blame] | 699 | "PEL severity informational or recovered. no quiesce needed"); |
| Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 700 | return; |
| 701 | } |
| 702 | if (!_logManager.isQuiesceOnErrorEnabled()) |
| 703 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 704 | lg2::debug("QuiesceOnHwError not enabled, no quiesce needed"); |
| Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 705 | return; |
| 706 | } |
| 707 | |
| Matt Spinler | 845c624 | 2022-03-01 16:45:08 -0600 | [diff] [blame] | 708 | CreatorID creatorID{pel->privateHeader().creatorID()}; |
| 709 | |
| 710 | if ((creatorID != CreatorID::openBMC) && |
| 711 | (creatorID != CreatorID::hostboot) && |
| 712 | (creatorID != CreatorID::ioDrawer) && (creatorID != CreatorID::occ) && |
| 713 | (creatorID != CreatorID::phyp)) |
| 714 | { |
| 715 | return; |
| 716 | } |
| 717 | |
| Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 718 | // Now check if it has any type of callout |
| Andrew Geissler | f8e750d | 2022-01-14 14:56:13 -0600 | [diff] [blame] | 719 | if (pel->isHwCalloutPresent()) |
| Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 720 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 721 | lg2::info( |
| Matt Spinler | b2abc04 | 2021-05-17 15:32:50 -0600 | [diff] [blame] | 722 | "QuiesceOnHwError enabled, PEL severity not nonError or recovered, " |
| 723 | "and callout is present"); |
| Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 724 | |
| 725 | _logManager.quiesceOnError(pel->obmcLogID()); |
| 726 | } |
| 727 | } |
| 728 | |
| Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 729 | std::string Manager::getEventId(const openpower::pels::PEL& pel) const |
| 730 | { |
| 731 | std::string str; |
| 732 | auto src = pel.primarySRC(); |
| 733 | if (src) |
| 734 | { |
| 735 | const auto& hexwords = (*src)->hexwordData(); |
| 736 | |
| 737 | std::string refcode = (*src)->asciiString(); |
| 738 | size_t pos = refcode.find_last_not_of(0x20); |
| 739 | if (pos != std::string::npos) |
| 740 | { |
| 741 | refcode.erase(pos + 1); |
| 742 | } |
| 743 | str = refcode; |
| 744 | |
| 745 | for (auto& value : hexwords) |
| 746 | { |
| 747 | str += " "; |
| 748 | str += getNumberString("%08X", value); |
| 749 | } |
| 750 | } |
| Matt Spinler | 0003af1 | 2022-06-08 10:46:17 -0500 | [diff] [blame] | 751 | return sanitizeFieldForDBus(str); |
| Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | void Manager::updateEventId(std::unique_ptr<openpower::pels::PEL>& pel) |
| 755 | { |
| 756 | std::string eventIdStr = getEventId(*pel); |
| 757 | |
| 758 | auto entryN = _logManager.entries.find(pel->obmcLogID()); |
| 759 | if (entryN != _logManager.entries.end()) |
| 760 | { |
| Matt Spinler | b25e8a3 | 2023-06-07 16:05:36 -0500 | [diff] [blame] | 761 | entryN->second->eventId(eventIdStr, true); |
| Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | |
| Matt Spinler | 0003af1 | 2022-06-08 10:46:17 -0500 | [diff] [blame] | 765 | std::string Manager::sanitizeFieldForDBus(std::string field) |
| 766 | { |
| 767 | std::for_each(field.begin(), field.end(), [](char& ch) { |
| 768 | if (((ch < ' ') || (ch > '~')) && (ch != '\n') && (ch != '\t')) |
| 769 | { |
| 770 | ch = ' '; |
| 771 | } |
| 772 | }); |
| 773 | return field; |
| 774 | } |
| 775 | |
| Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 776 | std::string Manager::getResolution(const openpower::pels::PEL& pel) const |
| 777 | { |
| 778 | std::string str; |
| 779 | std::string resolution; |
| 780 | auto src = pel.primarySRC(); |
| 781 | if (src) |
| 782 | { |
| 783 | // First extract the callout pointer and then go through |
| 784 | const auto& callouts = (*src)->callouts(); |
| 785 | namespace pv = openpower::pels::pel_values; |
| 786 | // All PELs dont have callout, check before parsing callout data |
| 787 | if (callouts) |
| 788 | { |
| 789 | const auto& entries = callouts->callouts(); |
| 790 | // Entry starts with index 1 |
| 791 | uint8_t index = 1; |
| 792 | for (auto& entry : entries) |
| 793 | { |
| 794 | resolution += std::to_string(index) + ". "; |
| 795 | // Adding Location code to resolution |
| 796 | if (!entry->locationCode().empty()) |
| Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 797 | resolution += "Location Code: " + entry->locationCode() + |
| 798 | ", "; |
| Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 799 | if (entry->fruIdentity()) |
| 800 | { |
| 801 | // Get priority and set the resolution string |
| 802 | str = pv::getValue(entry->priority(), |
| 803 | pel_values::calloutPriorityValues, |
| 804 | pel_values::registryNamePos); |
| 805 | str[0] = toupper(str[0]); |
| 806 | resolution += "Priority: " + str + ", "; |
| 807 | if (entry->fruIdentity()->getPN().has_value()) |
| 808 | { |
| 809 | resolution += |
| 810 | "PN: " + entry->fruIdentity()->getPN().value() + |
| 811 | ", "; |
| 812 | } |
| 813 | if (entry->fruIdentity()->getSN().has_value()) |
| 814 | { |
| 815 | resolution += |
| 816 | "SN: " + entry->fruIdentity()->getSN().value() + |
| 817 | ", "; |
| 818 | } |
| 819 | if (entry->fruIdentity()->getCCIN().has_value()) |
| 820 | { |
| 821 | resolution += |
| 822 | "CCIN: " + entry->fruIdentity()->getCCIN().value() + |
| 823 | ", "; |
| 824 | } |
| 825 | // Add the maintenance procedure |
| 826 | if (entry->fruIdentity()->getMaintProc().has_value()) |
| 827 | { |
| 828 | resolution += |
| 829 | "Procedure: " + |
| 830 | entry->fruIdentity()->getMaintProc().value() + ", "; |
| 831 | } |
| 832 | } |
| 833 | resolution.resize(resolution.size() - 2); |
| 834 | resolution += "\n"; |
| 835 | index++; |
| 836 | } |
| 837 | } |
| 838 | } |
| Matt Spinler | 0003af1 | 2022-06-08 10:46:17 -0500 | [diff] [blame] | 839 | return sanitizeFieldForDBus(resolution); |
| Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 840 | } |
| 841 | |
| Matt Spinler | 28d6ae2 | 2022-03-18 11:18:27 -0500 | [diff] [blame] | 842 | bool Manager::updateResolution(const openpower::pels::PEL& pel) |
| Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 843 | { |
| Matt Spinler | 28d6ae2 | 2022-03-18 11:18:27 -0500 | [diff] [blame] | 844 | std::string callouts = getResolution(pel); |
| 845 | auto entryN = _logManager.entries.find(pel.obmcLogID()); |
| Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 846 | if (entryN != _logManager.entries.end()) |
| 847 | { |
| Matt Spinler | 734ed2b | 2022-01-21 09:31:46 -0600 | [diff] [blame] | 848 | entryN->second->resolution(callouts, true); |
| Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 849 | } |
| Matt Spinler | 28d6ae2 | 2022-03-18 11:18:27 -0500 | [diff] [blame] | 850 | |
| 851 | return false; |
| Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 852 | } |
| 853 | |
| Matt Spinler | 3387eac | 2023-07-06 14:56:02 -0500 | [diff] [blame] | 854 | void Manager::serializeLogEntry(uint32_t obmcLogID) |
| 855 | { |
| 856 | auto entryN = _logManager.entries.find(obmcLogID); |
| 857 | if (entryN != _logManager.entries.end()) |
| 858 | { |
| 859 | serialize(*entryN->second); |
| 860 | } |
| 861 | } |
| 862 | |
| Matt Spinler | 8b81ec0 | 2022-07-12 13:25:37 -0500 | [diff] [blame] | 863 | void Manager::updateDBusSeverity(const openpower::pels::PEL& pel) |
| 864 | { |
| 865 | // The final severity of the PEL may not agree with the |
| 866 | // original severity of the D-Bus event log. Update the |
| 867 | // D-Bus property to match in some cases. This is to |
| 868 | // ensure there isn't a Critical or Warning Redfish event |
| 869 | // log for an informational or recovered PEL (or vice versa). |
| 870 | // This doesn't make an explicit call to serialize the new |
| 871 | // event log property value because updateEventId() is called |
| 872 | // right after this and will do it. |
| 873 | auto sevType = |
| 874 | static_cast<SeverityType>(pel.userHeader().severity() & 0xF0); |
| 875 | |
| 876 | auto entryN = _logManager.entries.find(pel.obmcLogID()); |
| 877 | if (entryN != _logManager.entries.end()) |
| 878 | { |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 879 | auto newSeverity = |
| 880 | fixupLogSeverity(entryN->second->severity(), sevType); |
| Matt Spinler | 8b81ec0 | 2022-07-12 13:25:37 -0500 | [diff] [blame] | 881 | if (newSeverity) |
| 882 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 883 | lg2::info("Changing event log {ID} severity from {OLD} " |
| 884 | "to {NEW} to match PEL", |
| 885 | "ID", lg2::hex, entryN->second->id(), "OLD", |
| 886 | Entry::convertLevelToString(entryN->second->severity()), |
| 887 | "NEW", Entry::convertLevelToString(*newSeverity)); |
| Matt Spinler | 8b81ec0 | 2022-07-12 13:25:37 -0500 | [diff] [blame] | 888 | |
| 889 | entryN->second->severity(*newSeverity, true); |
| 890 | } |
| 891 | } |
| 892 | } |
| 893 | |
| Adriana Kobylak | e7d271a | 2020-12-07 14:32:44 -0600 | [diff] [blame] | 894 | void Manager::setEntryPath(uint32_t obmcLogID) |
| 895 | { |
| 896 | Repository::LogID id{Repository::LogID::Obmc(obmcLogID)}; |
| 897 | if (auto attributes = _repo.getPELAttributes(id); attributes) |
| 898 | { |
| 899 | auto& attr = attributes.value().get(); |
| 900 | auto entry = _logManager.entries.find(obmcLogID); |
| 901 | if (entry != _logManager.entries.end()) |
| 902 | { |
| Matt Spinler | 734ed2b | 2022-01-21 09:31:46 -0600 | [diff] [blame] | 903 | entry->second->path(attr.path, true); |
| Adriana Kobylak | e7d271a | 2020-12-07 14:32:44 -0600 | [diff] [blame] | 904 | } |
| 905 | } |
| 906 | } |
| 907 | |
| Vijay Lobo | cbc93a4 | 2021-05-20 19:04:07 -0500 | [diff] [blame] | 908 | void Manager::setServiceProviderNotifyFlag(uint32_t obmcLogID) |
| 909 | { |
| 910 | Repository::LogID id{Repository::LogID::Obmc(obmcLogID)}; |
| 911 | if (auto attributes = _repo.getPELAttributes(id); attributes) |
| 912 | { |
| 913 | auto& attr = attributes.value().get(); |
| 914 | auto entry = _logManager.entries.find(obmcLogID); |
| 915 | if (entry != _logManager.entries.end()) |
| 916 | { |
| Lakshmi Yadlapati | 7a3ede5 | 2022-11-18 13:26:17 -0600 | [diff] [blame] | 917 | if (attr.actionFlags.test(callHomeFlagBit)) |
| 918 | { |
| Matt Spinler | b25e8a3 | 2023-06-07 16:05:36 -0500 | [diff] [blame] | 919 | entry->second->serviceProviderNotify(Entry::Notify::Notify, |
| 920 | true); |
| Lakshmi Yadlapati | 7a3ede5 | 2022-11-18 13:26:17 -0600 | [diff] [blame] | 921 | } |
| 922 | else |
| 923 | { |
| Matt Spinler | b25e8a3 | 2023-06-07 16:05:36 -0500 | [diff] [blame] | 924 | entry->second->serviceProviderNotify(Entry::Notify::Inhibit, |
| 925 | true); |
| Lakshmi Yadlapati | 7a3ede5 | 2022-11-18 13:26:17 -0600 | [diff] [blame] | 926 | } |
| Vijay Lobo | cbc93a4 | 2021-05-20 19:04:07 -0500 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | } |
| 930 | |
| Matt Spinler | 734ed2b | 2022-01-21 09:31:46 -0600 | [diff] [blame] | 931 | void Manager::createPELEntry(uint32_t obmcLogID, bool skipIaSignal) |
| Vijay Lobo | afb1b46 | 2021-07-21 23:29:13 -0500 | [diff] [blame] | 932 | { |
| 933 | std::map<std::string, PropertiesVariant> varData; |
| 934 | Repository::LogID id{Repository::LogID::Obmc(obmcLogID)}; |
| 935 | if (auto attributes = _repo.getPELAttributes(id); attributes) |
| 936 | { |
| 937 | namespace pv = openpower::pels::pel_values; |
| 938 | auto& attr = attributes.value().get(); |
| Vijay Lobo | b2e541e | 2021-08-31 23:12:47 -0500 | [diff] [blame] | 939 | |
| 940 | // get the hidden flag values |
| 941 | auto sevType = static_cast<SeverityType>(attr.severity & 0xF0); |
| 942 | auto isHidden = true; |
| 943 | if (((sevType != SeverityType::nonError) && |
| 944 | attr.actionFlags.test(reportFlagBit) && |
| 945 | !attr.actionFlags.test(hiddenFlagBit)) || |
| 946 | ((sevType == SeverityType::nonError) && |
| 947 | attr.actionFlags.test(serviceActionFlagBit))) |
| 948 | { |
| 949 | isHidden = false; |
| 950 | } |
| 951 | varData.emplace(std::string("Hidden"), isHidden); |
| Vijay Lobo | afb1b46 | 2021-07-21 23:29:13 -0500 | [diff] [blame] | 952 | varData.emplace( |
| 953 | std::string("Subsystem"), |
| 954 | pv::getValue(attr.subsystem, pel_values::subsystemValues)); |
| Vijay Lobo | 2fb1021 | 2021-08-22 23:24:16 -0500 | [diff] [blame] | 955 | |
| 956 | varData.emplace( |
| 957 | std::string("ManagementSystemAck"), |
| 958 | (attr.hmcState == TransmissionState::acked ? true : false)); |
| 959 | |
| Matt Spinler | 8e65f4e | 2023-05-02 13:40:08 -0500 | [diff] [blame] | 960 | varData.emplace("PlatformLogID", attr.plid); |
| 961 | varData.emplace("Deconfig", attr.deconfig); |
| 962 | varData.emplace("Guard", attr.guard); |
| 963 | varData.emplace("Timestamp", attr.creationTime); |
| 964 | |
| Vijay Lobo | afb1b46 | 2021-07-21 23:29:13 -0500 | [diff] [blame] | 965 | // Path to create PELEntry Interface is same as PEL |
| 966 | auto path = std::string(OBJ_ENTRY) + '/' + std::to_string(obmcLogID); |
| 967 | // Create Interface for PELEntry and set properties |
| Vijay Lobo | 2fb1021 | 2021-08-22 23:24:16 -0500 | [diff] [blame] | 968 | auto pelEntry = std::make_unique<PELEntry>(_logManager.getBus(), path, |
| 969 | varData, obmcLogID, &_repo); |
| Matt Spinler | 734ed2b | 2022-01-21 09:31:46 -0600 | [diff] [blame] | 970 | if (!skipIaSignal) |
| 971 | { |
| 972 | pelEntry->emit_added(); |
| 973 | } |
| Vijay Lobo | afb1b46 | 2021-07-21 23:29:13 -0500 | [diff] [blame] | 974 | _pelEntries.emplace(std::move(path), std::move(pelEntry)); |
| 975 | } |
| 976 | } |
| 977 | |
| Ramesh Iyyar | f4203c4 | 2021-06-24 06:09:23 -0500 | [diff] [blame] | 978 | uint32_t Manager::getPELIdFromBMCLogId(uint32_t bmcLogId) |
| 979 | { |
| 980 | Repository::LogID id{Repository::LogID::Obmc(bmcLogId)}; |
| 981 | if (auto logId = _repo.getLogID(id); !logId.has_value()) |
| 982 | { |
| 983 | throw common_error::InvalidArgument(); |
| 984 | } |
| 985 | else |
| 986 | { |
| 987 | return logId->pelID.id; |
| 988 | } |
| 989 | } |
| 990 | |
| Ramesh Iyyar | 530efbf | 2021-06-24 06:22:22 -0500 | [diff] [blame] | 991 | uint32_t Manager::getBMCLogIdFromPELId(uint32_t pelId) |
| 992 | { |
| 993 | Repository::LogID id{Repository::LogID::Pel(pelId)}; |
| 994 | if (auto logId = _repo.getLogID(id); !logId.has_value()) |
| 995 | { |
| 996 | throw common_error::InvalidArgument(); |
| 997 | } |
| 998 | else |
| 999 | { |
| 1000 | return logId->obmcID.id; |
| 1001 | } |
| 1002 | } |
| 1003 | |
| Patrick Williams | 2529115 | 2025-02-01 08:21:42 -0500 | [diff] [blame] | 1004 | void Manager::updateProgressSRC( |
| 1005 | std::unique_ptr<openpower::pels::PEL>& pel) const |
| Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 1006 | { |
| Matt Spinler | 931cafe | 2025-04-22 12:31:28 -0500 | [diff] [blame] | 1007 | const size_t refcodeBegin = 40; |
| 1008 | const size_t refcodeSize = 8; |
| 1009 | |
| Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 1010 | // Check for pel severity of type - 0x51 = critical error, system |
| 1011 | // termination |
| 1012 | if (pel->userHeader().severity() == 0x51) |
| 1013 | { |
| 1014 | auto src = pel->primarySRC(); |
| 1015 | if (src) |
| 1016 | { |
| 1017 | std::vector<uint8_t> asciiSRC = (*src)->getSrcStruct(); |
| Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 1018 | |
| Matt Spinler | 931cafe | 2025-04-22 12:31:28 -0500 | [diff] [blame] | 1019 | if (asciiSRC.size() < (refcodeBegin + refcodeSize)) |
| Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 1020 | { |
| Matt Spinler | 931cafe | 2025-04-22 12:31:28 -0500 | [diff] [blame] | 1021 | lg2::error( |
| 1022 | "SRC struct is too short to get progress code ({SIZE})", |
| 1023 | "SIZE", asciiSRC.size()); |
| 1024 | return; |
| Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 1025 | } |
| 1026 | |
| Matt Spinler | 931cafe | 2025-04-22 12:31:28 -0500 | [diff] [blame] | 1027 | // Pull the ASCII SRC from offset [40-47] e.g. BD8D1001 |
| 1028 | std::vector<uint8_t> srcRefCode( |
| 1029 | asciiSRC.begin() + refcodeBegin, |
| 1030 | asciiSRC.begin() + refcodeBegin + refcodeSize); |
| 1031 | |
| Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 1032 | try |
| 1033 | { |
| 1034 | _dataIface->createProgressSRC(srcRefCode, asciiSRC); |
| 1035 | } |
| Matt Spinler | 87f3924 | 2023-05-01 11:36:18 -0500 | [diff] [blame] | 1036 | catch (const std::exception&) |
| Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 1037 | { |
| 1038 | // Exception - may be no boot progress interface on dbus |
| 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | } |
| 1043 | |
| Matt Spinler | d8fb5ba | 2022-01-25 13:01:14 -0600 | [diff] [blame] | 1044 | void Manager::scheduleObmcLogDelete(uint32_t obmcLogID) |
| 1045 | { |
| 1046 | _obmcLogDeleteEventSource = std::make_unique<sdeventplus::source::Defer>( |
| 1047 | _event, std::bind(std::mem_fn(&Manager::deleteObmcLog), this, |
| 1048 | std::placeholders::_1, obmcLogID)); |
| 1049 | } |
| 1050 | |
| 1051 | void Manager::deleteObmcLog(sdeventplus::source::EventBase&, uint32_t obmcLogID) |
| 1052 | { |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 1053 | lg2::info("Removing event log with no PEL: {BMCID}", "BMCID", obmcLogID); |
| Matt Spinler | d8fb5ba | 2022-01-25 13:01:14 -0600 | [diff] [blame] | 1054 | _logManager.erase(obmcLogID); |
| 1055 | _obmcLogDeleteEventSource.reset(); |
| 1056 | } |
| 1057 | |
| Matt Spinler | 0dd22c8 | 2023-05-04 15:28:12 -0500 | [diff] [blame] | 1058 | bool Manager::clearPowerThermalDeconfigFlag(const std::string& locationCode, |
| 1059 | openpower::pels::PEL& pel) |
| 1060 | { |
| 1061 | // The requirements state that only power-thermal or |
| 1062 | // fan PELs need their deconfig flag cleared. |
| 1063 | static const std::vector<uint32_t> compIDs{bmcThermalCompID, bmcFansCompID}; |
| 1064 | |
| 1065 | if (std::find(compIDs.begin(), compIDs.end(), |
| 1066 | pel.privateHeader().header().componentID) == compIDs.end()) |
| 1067 | { |
| 1068 | return false; |
| 1069 | } |
| 1070 | |
| 1071 | auto src = pel.primarySRC(); |
| 1072 | const auto& callouts = (*src)->callouts(); |
| 1073 | if (!callouts) |
| 1074 | { |
| 1075 | return false; |
| 1076 | } |
| 1077 | |
| 1078 | for (const auto& callout : callouts->callouts()) |
| 1079 | { |
| 1080 | // Look for the passed in location code in a callout that |
| 1081 | // is either a normal HW callout or a symbolic FRU with |
| 1082 | // a trusted location code callout. |
| 1083 | if ((callout->locationCode() != locationCode) || |
| 1084 | !callout->fruIdentity()) |
| 1085 | { |
| 1086 | continue; |
| 1087 | } |
| 1088 | |
| 1089 | if ((callout->fruIdentity()->failingComponentType() != |
| 1090 | src::FRUIdentity::hardwareFRU) && |
| 1091 | (callout->fruIdentity()->failingComponentType() != |
| 1092 | src::FRUIdentity::symbolicFRUTrustedLocCode)) |
| 1093 | { |
| 1094 | continue; |
| 1095 | } |
| 1096 | |
| Matt Spinler | fbdfc76 | 2023-06-30 15:15:44 -0500 | [diff] [blame] | 1097 | lg2::info( |
| 1098 | "Clearing deconfig flag in PEL {ID} with SRC {SRC} because {LOC} was replaced", |
| 1099 | "ID", lg2::hex, pel.id(), "SRC", (*src)->asciiString().substr(0, 8), |
| 1100 | "LOC", locationCode); |
| Matt Spinler | 0dd22c8 | 2023-05-04 15:28:12 -0500 | [diff] [blame] | 1101 | (*src)->clearErrorStatusFlag(SRC::ErrorStatusFlags::deconfigured); |
| 1102 | return true; |
| 1103 | } |
| 1104 | return false; |
| 1105 | } |
| 1106 | |
| 1107 | void Manager::hardwarePresent(const std::string& locationCode) |
| 1108 | { |
| 1109 | Repository::PELUpdateFunc handlePowerThermalHardwarePresent = |
| 1110 | [locationCode](openpower::pels::PEL& pel) { |
| Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 1111 | return Manager::clearPowerThermalDeconfigFlag(locationCode, pel); |
| 1112 | }; |
| Matt Spinler | 0dd22c8 | 2023-05-04 15:28:12 -0500 | [diff] [blame] | 1113 | |
| 1114 | // If the PEL was created by the BMC and has the deconfig flag set, |
| 1115 | // it's a candidate to have the deconfig flag cleared. |
| 1116 | for (const auto& [id, attributes] : _repo.getAttributesMap()) |
| 1117 | { |
| 1118 | if ((attributes.creator == static_cast<uint8_t>(CreatorID::openBMC)) && |
| 1119 | attributes.deconfig) |
| 1120 | { |
| Matt Spinler | 1cb59f7 | 2023-07-20 09:49:50 -0500 | [diff] [blame] | 1121 | auto updated = _repo.updatePEL(attributes.path, |
| 1122 | handlePowerThermalHardwarePresent); |
| 1123 | |
| 1124 | if (updated) |
| 1125 | { |
| 1126 | // Also update the property on D-Bus |
| 1127 | auto objPath = std::string(OBJ_ENTRY) + '/' + |
| 1128 | std::to_string(id.obmcID.id); |
| 1129 | auto entryN = _pelEntries.find(objPath); |
| 1130 | if (entryN != _pelEntries.end()) |
| 1131 | { |
| 1132 | entryN->second->deconfig(false); |
| 1133 | } |
| 1134 | else |
| 1135 | { |
| 1136 | lg2::error( |
| 1137 | "Could not find PEL Entry D-Bus object for {PATH}", |
| 1138 | "PATH", objPath); |
| 1139 | } |
| 1140 | } |
| Matt Spinler | 0dd22c8 | 2023-05-04 15:28:12 -0500 | [diff] [blame] | 1141 | } |
| 1142 | } |
| 1143 | } |
| 1144 | |
| Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 1145 | } // namespace pels |
| 1146 | } // namespace openpower |