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 | */ |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 16 | #include "user_header.hpp" |
| 17 | |
Harisuddin Mohamed Isa | 600d15a | 2019-12-20 12:42:26 +0800 | [diff] [blame] | 18 | #include "json_utils.hpp" |
Matt Spinler | 1a94cc3 | 2019-09-11 13:32:12 -0500 | [diff] [blame] | 19 | #include "pel_types.hpp" |
Aatir | c148935 | 2019-12-09 13:13:20 -0600 | [diff] [blame] | 20 | #include "pel_values.hpp" |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 21 | #include "severity.hpp" |
Matt Spinler | 1a94cc3 | 2019-09-11 13:32:12 -0500 | [diff] [blame] | 22 | |
Sumit Kumar | 50bfa69 | 2022-01-06 06:48:26 -0600 | [diff] [blame] | 23 | #include <fmt/format.h> |
| 24 | |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 25 | #include <iostream> |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 26 | #include <phosphor-logging/log.hpp> |
| 27 | |
| 28 | namespace openpower |
| 29 | { |
| 30 | namespace pels |
| 31 | { |
| 32 | |
Aatir | c148935 | 2019-12-09 13:13:20 -0600 | [diff] [blame] | 33 | namespace pv = openpower::pels::pel_values; |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 34 | using namespace phosphor::logging; |
| 35 | |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 36 | void UserHeader::unflatten(Stream& stream) |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 37 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 38 | stream >> _header >> _eventSubsystem >> _eventScope >> _eventSeverity >> |
| 39 | _eventType >> _reserved4Byte1 >> _problemDomain >> _problemVector >> |
Matt Spinler | eb11144 | 2019-11-07 13:05:36 -0600 | [diff] [blame] | 40 | _actionFlags >> _states; |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 41 | } |
| 42 | |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 43 | void UserHeader::flatten(Stream& stream) const |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 44 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 45 | stream << _header << _eventSubsystem << _eventScope << _eventSeverity |
| 46 | << _eventType << _reserved4Byte1 << _problemDomain << _problemVector |
Matt Spinler | eb11144 | 2019-11-07 13:05:36 -0600 | [diff] [blame] | 47 | << _actionFlags << _states; |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 50 | UserHeader::UserHeader(const message::Entry& entry, |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 51 | phosphor::logging::Entry::Level severity, |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 52 | const AdditionalData& additionalData, |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 53 | const DataInterfaceBase& dataIface) |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 54 | { |
| 55 | _header.id = static_cast<uint16_t>(SectionID::userHeader); |
| 56 | _header.size = UserHeader::flattenedSize(); |
| 57 | _header.version = userHeaderVersion; |
| 58 | _header.subType = 0; |
| 59 | _header.componentID = static_cast<uint16_t>(ComponentID::phosphorLogging); |
| 60 | |
Matt Spinler | 23970b0 | 2022-02-25 16:34:46 -0600 | [diff] [blame] | 61 | std::optional<uint8_t> subsys; |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 62 | |
Sumit Kumar | 50bfa69 | 2022-01-06 06:48:26 -0600 | [diff] [blame] | 63 | // Check for additional data - PEL_SUBSYSTEM |
| 64 | auto ss = additionalData.getValue("PEL_SUBSYSTEM"); |
| 65 | if (ss) |
| 66 | { |
| 67 | auto eventSubsystem = std::stoul(*ss, NULL, 16); |
Matt Spinler | 23970b0 | 2022-02-25 16:34:46 -0600 | [diff] [blame] | 68 | std::string subsystemString = |
Sumit Kumar | 50bfa69 | 2022-01-06 06:48:26 -0600 | [diff] [blame] | 69 | pv::getValue(eventSubsystem, pel_values::subsystemValues); |
Matt Spinler | 23970b0 | 2022-02-25 16:34:46 -0600 | [diff] [blame] | 70 | if (subsystemString == "invalid") |
Sumit Kumar | 50bfa69 | 2022-01-06 06:48:26 -0600 | [diff] [blame] | 71 | { |
| 72 | log<level::WARNING>( |
Matt Spinler | 23970b0 | 2022-02-25 16:34:46 -0600 | [diff] [blame] | 73 | fmt::format( |
| 74 | "UH: Invalid SubSystem value in PEL_SUBSYSTEM: {:#X}", |
| 75 | eventSubsystem) |
Sumit Kumar | 50bfa69 | 2022-01-06 06:48:26 -0600 | [diff] [blame] | 76 | .c_str()); |
| 77 | } |
| 78 | else |
| 79 | { |
Matt Spinler | 23970b0 | 2022-02-25 16:34:46 -0600 | [diff] [blame] | 80 | subsys = eventSubsystem; |
Sumit Kumar | 50bfa69 | 2022-01-06 06:48:26 -0600 | [diff] [blame] | 81 | } |
| 82 | } |
Matt Spinler | 23970b0 | 2022-02-25 16:34:46 -0600 | [diff] [blame] | 83 | else |
| 84 | { |
| 85 | subsys = entry.subsystem; |
| 86 | } |
| 87 | |
| 88 | if (subsys) |
| 89 | { |
| 90 | _eventSubsystem = *subsys; |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | // Gotta use something, how about 'others'. |
| 95 | log<level::WARNING>( |
| 96 | "No PEL subystem value supplied for error, using 'others'"); |
| 97 | _eventSubsystem = 0x70; |
| 98 | } |
Sumit Kumar | 50bfa69 | 2022-01-06 06:48:26 -0600 | [diff] [blame] | 99 | |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 100 | _eventScope = entry.eventScope.value_or( |
| 101 | static_cast<uint8_t>(EventScope::entirePlatform)); |
| 102 | |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 103 | { |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 104 | bool mfgSevStatus = false; |
| 105 | bool mfgActionFlagStatus = false; |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 106 | |
| 107 | // Get the mfg severity & action flags |
| 108 | if (entry.mfgSeverity || entry.mfgActionFlags) |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 109 | { |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 110 | std::optional<uint8_t> sev = std::nullopt; |
| 111 | uint16_t val = 0; |
| 112 | |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 113 | if (entry.mfgSeverity) |
| 114 | { |
| 115 | // Find the mf severity possibly dependent on the system type. |
| 116 | sev = getSeverity(entry.mfgSeverity.value(), dataIface); |
| 117 | } |
| 118 | |
| 119 | if (entry.mfgActionFlags) |
| 120 | { |
| 121 | // Find the mfg action flags |
| 122 | val = entry.mfgActionFlags.value(); |
| 123 | } |
| 124 | |
| 125 | if (sev || val) |
| 126 | { |
| 127 | bool mfgProp = dataIface.getQuiesceOnError(); |
| 128 | if (mfgProp) |
| 129 | { |
| 130 | if (sev) |
| 131 | { |
| 132 | _eventSeverity = *sev; |
| 133 | mfgSevStatus = true; |
| 134 | } |
| 135 | |
| 136 | if (val) |
| 137 | { |
| 138 | _actionFlags = val; |
| 139 | mfgActionFlagStatus = true; |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | if (!mfgSevStatus) |
| 146 | { |
| 147 | // Get the severity from the registry if it's there, otherwise get |
| 148 | // it from the OpenBMC event log severity value. |
| 149 | if (!entry.severity) |
| 150 | { |
| 151 | _eventSeverity = convertOBMCSeverityToPEL(severity); |
| 152 | } |
| 153 | else |
| 154 | { |
| 155 | // Find the severity possibly dependent on the system type. |
| 156 | auto sev = getSeverity(entry.severity.value(), dataIface); |
| 157 | if (sev) |
| 158 | { |
| 159 | _eventSeverity = *sev; |
| 160 | } |
| 161 | else |
| 162 | { |
| 163 | // Either someone screwed up the message registry |
| 164 | // or getSystemNames failed. |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 165 | log<level::ERR>( |
| 166 | "Failed finding the severity in the message registry", |
| 167 | phosphor::logging::entry("ERROR=%s", |
| 168 | entry.name.c_str())); |
| 169 | |
| 170 | // Have to choose something, just use informational. |
| 171 | _eventSeverity = 0; |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | // Convert Critical error (0x50) to Critical Error-System Termination |
| 177 | // (0x51), if the AdditionalData is set to SYSTEM_TERM |
| 178 | auto sevLevel = additionalData.getValue("SEVERITY_DETAIL"); |
| 179 | if ((_eventSeverity & 0xF0) == 0x50) |
| 180 | { |
| 181 | if (sevLevel.value_or("") == "SYSTEM_TERM") |
| 182 | { |
| 183 | // Change to Critical Error, System Termination |
| 184 | _eventSeverity = 0x51; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | if (entry.eventType) |
| 189 | { |
| 190 | _eventType = *entry.eventType; |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 191 | } |
| 192 | else |
| 193 | { |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 194 | // There are different default event types for info errors |
| 195 | // vs non info ones. |
| 196 | auto sevType = static_cast<SeverityType>(_eventSeverity & 0xF0); |
| 197 | _eventType = |
| 198 | (sevType == SeverityType::nonError) |
| 199 | ? static_cast<uint8_t>(EventType::miscInformational) |
| 200 | : static_cast<uint8_t>(EventType::notApplicable); |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 201 | } |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 202 | |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 203 | _reserved4Byte1 = 0; |
| 204 | |
| 205 | // No uses for problem domain or vector |
| 206 | _problemDomain = 0; |
| 207 | _problemVector = 0; |
| 208 | |
| 209 | // These will be set in pel_rules::check() if they're still |
| 210 | // at the default value. |
| 211 | if (!mfgActionFlagStatus) |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 212 | { |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 213 | _actionFlags = entry.actionFlags.value_or(actionFlagsDefault); |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 214 | } |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 215 | |
| 216 | _states = 0; |
| 217 | |
| 218 | _valid = true; |
Vijay Lobo | 6b3f345 | 2021-04-15 23:04:42 -0500 | [diff] [blame] | 219 | } |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 220 | } |
| 221 | |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 222 | UserHeader::UserHeader(Stream& pel) |
| 223 | { |
| 224 | try |
| 225 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 226 | unflatten(pel); |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 227 | validate(); |
| 228 | } |
| 229 | catch (const std::exception& e) |
| 230 | { |
| 231 | log<level::ERR>("Cannot unflatten user header", |
| 232 | entry("ERROR=%s", e.what())); |
| 233 | _valid = false; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | void UserHeader::validate() |
| 238 | { |
| 239 | bool failed = false; |
Matt Spinler | 1a94cc3 | 2019-09-11 13:32:12 -0500 | [diff] [blame] | 240 | if (header().id != static_cast<uint16_t>(SectionID::userHeader)) |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 241 | { |
| 242 | log<level::ERR>("Invalid user header section ID", |
| 243 | entry("ID=0x%X", header().id)); |
| 244 | failed = true; |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | if (header().version != userHeaderVersion) |
| 248 | { |
| 249 | log<level::ERR>("Invalid user header version", |
| 250 | entry("VERSION=0x%X", header().version)); |
| 251 | failed = true; |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | _valid = (failed) ? false : true; |
| 255 | } |
| 256 | |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 257 | std::optional<std::string> UserHeader::getJSON() const |
| 258 | { |
| 259 | std::string severity; |
| 260 | std::string subsystem; |
| 261 | std::string eventScope; |
| 262 | std::string eventType; |
Harisuddin Mohamed Isa | 600d15a | 2019-12-20 12:42:26 +0800 | [diff] [blame] | 263 | std::vector<std::string> actionFlags; |
Aatir | c148935 | 2019-12-09 13:13:20 -0600 | [diff] [blame] | 264 | severity = pv::getValue(_eventSeverity, pel_values::severityValues); |
| 265 | subsystem = pv::getValue(_eventSubsystem, pel_values::subsystemValues); |
| 266 | eventScope = pv::getValue(_eventScope, pel_values::eventScopeValues); |
| 267 | eventType = pv::getValue(_eventType, pel_values::eventTypeValues); |
Harisuddin Mohamed Isa | 600d15a | 2019-12-20 12:42:26 +0800 | [diff] [blame] | 268 | actionFlags = |
| 269 | pv::getValuesBitwise(_actionFlags, pel_values::actionFlagsValues); |
Matt Spinler | 455587e | 2020-01-15 14:31:52 -0600 | [diff] [blame] | 270 | |
| 271 | std::string hostState{"Invalid"}; |
Vijay Lobo | 2fb1021 | 2021-08-22 23:24:16 -0500 | [diff] [blame] | 272 | std::string hmcState{"Invalid"}; |
Matt Spinler | 455587e | 2020-01-15 14:31:52 -0600 | [diff] [blame] | 273 | auto iter = pv::transmissionStates.find( |
| 274 | static_cast<TransmissionState>(hostTransmissionState())); |
| 275 | if (iter != pv::transmissionStates.end()) |
| 276 | { |
| 277 | hostState = iter->second; |
| 278 | } |
Vijay Lobo | 2fb1021 | 2021-08-22 23:24:16 -0500 | [diff] [blame] | 279 | auto iter1 = pv::transmissionStates.find( |
| 280 | static_cast<TransmissionState>(hmcTransmissionState())); |
| 281 | if (iter1 != pv::transmissionStates.end()) |
| 282 | { |
| 283 | hmcState = iter1->second; |
| 284 | } |
Matt Spinler | 455587e | 2020-01-15 14:31:52 -0600 | [diff] [blame] | 285 | |
Harisuddin Mohamed Isa | 600d15a | 2019-12-20 12:42:26 +0800 | [diff] [blame] | 286 | std::string uh; |
Harisuddin Mohamed Isa | bebeb94 | 2020-03-12 17:12:24 +0800 | [diff] [blame] | 287 | jsonInsert(uh, pv::sectionVer, getNumberString("%d", userHeaderVersion), 1); |
| 288 | jsonInsert(uh, pv::subSection, getNumberString("%d", _header.subType), 1); |
| 289 | jsonInsert(uh, "Log Committed by", |
| 290 | getNumberString("0x%X", _header.componentID), 1); |
Harisuddin Mohamed Isa | 600d15a | 2019-12-20 12:42:26 +0800 | [diff] [blame] | 291 | jsonInsert(uh, "Subsystem", subsystem, 1); |
| 292 | jsonInsert(uh, "Event Scope", eventScope, 1); |
| 293 | jsonInsert(uh, "Event Severity", severity, 1); |
| 294 | jsonInsert(uh, "Event Type", eventType, 1); |
| 295 | jsonInsertArray(uh, "Action Flags", actionFlags, 1); |
Matt Spinler | 455587e | 2020-01-15 14:31:52 -0600 | [diff] [blame] | 296 | jsonInsert(uh, "Host Transmission", hostState, 1); |
Vijay Lobo | 2fb1021 | 2021-08-22 23:24:16 -0500 | [diff] [blame] | 297 | jsonInsert(uh, "HMC Transmission", hmcState, 1); |
Harisuddin Mohamed Isa | 600d15a | 2019-12-20 12:42:26 +0800 | [diff] [blame] | 298 | uh.erase(uh.size() - 2); |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 299 | return uh; |
| 300 | } |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 301 | |
| 302 | std::optional<uint8_t> UserHeader::getSeverity( |
| 303 | const std::vector<message::RegistrySeverity>& severities, |
Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 304 | const DataInterfaceBase& dataIface) const |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 305 | { |
| 306 | const uint8_t* s = nullptr; |
Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 307 | std::vector<std::string> systemNames; |
| 308 | |
| 309 | // getSystemNames makes D-Bus calls, so only call it if we |
| 310 | // know we'll need it because there is a system name in the sev list |
| 311 | if (std::any_of(severities.begin(), severities.end(), |
| 312 | [](const auto& sev) { return !sev.system.empty(); })) |
| 313 | { |
| 314 | try |
| 315 | { |
| 316 | systemNames = dataIface.getSystemNames(); |
| 317 | } |
| 318 | catch (const std::exception& e) |
| 319 | { |
| 320 | log<level::ERR>("Failed trying to look up system names on D-Bus", |
| 321 | entry("ERROR=%s", e.what())); |
| 322 | return std::nullopt; |
| 323 | } |
| 324 | } |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 325 | |
| 326 | // Find the severity to use for this system type, or use the default |
| 327 | // entry (where no system type is specified). |
| 328 | for (const auto& sev : severities) |
| 329 | { |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 330 | if (std::find(systemNames.begin(), systemNames.end(), sev.system) != |
| 331 | systemNames.end()) |
Matt Spinler | aadccc8 | 2020-04-10 14:33:42 -0500 | [diff] [blame] | 332 | { |
| 333 | s = &sev.severity; |
| 334 | break; |
| 335 | } |
| 336 | else if (sev.system.empty()) |
| 337 | { |
| 338 | s = &sev.severity; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | if (s) |
| 343 | { |
| 344 | return *s; |
| 345 | } |
| 346 | |
| 347 | return std::nullopt; |
| 348 | } |
| 349 | |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 350 | } // namespace pels |
| 351 | } // namespace openpower |