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 | |
Matt Spinler | 1a94cc3 | 2019-09-11 13:32:12 -0500 | [diff] [blame] | 18 | #include "pel_types.hpp" |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 19 | #include "severity.hpp" |
Matt Spinler | 1a94cc3 | 2019-09-11 13:32:12 -0500 | [diff] [blame] | 20 | |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 21 | #include <phosphor-logging/log.hpp> |
| 22 | |
| 23 | namespace openpower |
| 24 | { |
| 25 | namespace pels |
| 26 | { |
| 27 | |
| 28 | using namespace phosphor::logging; |
| 29 | |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 30 | void UserHeader::unflatten(Stream& stream) |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 31 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 32 | stream >> _header >> _eventSubsystem >> _eventScope >> _eventSeverity >> |
| 33 | _eventType >> _reserved4Byte1 >> _problemDomain >> _problemVector >> |
| 34 | _actionFlags >> _reserved4Byte2; |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 35 | } |
| 36 | |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 37 | void UserHeader::flatten(Stream& stream) |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 38 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 39 | stream << _header << _eventSubsystem << _eventScope << _eventSeverity |
| 40 | << _eventType << _reserved4Byte1 << _problemDomain << _problemVector |
| 41 | << _actionFlags << _reserved4Byte2; |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 42 | } |
| 43 | |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 44 | UserHeader::UserHeader(const message::Entry& entry, |
| 45 | phosphor::logging::Entry::Level severity) |
| 46 | { |
| 47 | _header.id = static_cast<uint16_t>(SectionID::userHeader); |
| 48 | _header.size = UserHeader::flattenedSize(); |
| 49 | _header.version = userHeaderVersion; |
| 50 | _header.subType = 0; |
| 51 | _header.componentID = static_cast<uint16_t>(ComponentID::phosphorLogging); |
| 52 | |
| 53 | _eventSubsystem = entry.subsystem; |
| 54 | |
| 55 | _eventScope = entry.eventScope.value_or( |
| 56 | static_cast<uint8_t>(EventScope::entirePlatform)); |
| 57 | |
| 58 | // Get the severity from the registry if it's there, otherwise get it |
| 59 | // from the OpenBMC event log severity value. |
| 60 | _eventSeverity = |
| 61 | entry.severity.value_or(convertOBMCSeverityToPEL(severity)); |
| 62 | |
| 63 | // TODO: ibm-dev/dev/#1144 Handle manufacturing sev & action flags |
| 64 | |
| 65 | _eventType = entry.eventType.value_or( |
| 66 | static_cast<uint8_t>(EventType::notApplicable)); |
| 67 | |
| 68 | _reserved4Byte1 = 0; |
| 69 | |
| 70 | // No uses for problem domain or vector |
| 71 | _problemDomain = 0; |
| 72 | _problemVector = 0; |
| 73 | |
Matt Spinler | e07f915 | 2019-11-01 10:48:36 -0500 | [diff] [blame] | 74 | _actionFlags = entry.actionFlags.value_or(0); |
Matt Spinler | fdb6a20 | 2019-09-20 14:09:20 -0500 | [diff] [blame] | 75 | |
| 76 | _reserved4Byte2 = 0; |
| 77 | |
| 78 | _valid = true; |
| 79 | } |
| 80 | |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 81 | UserHeader::UserHeader(Stream& pel) |
| 82 | { |
| 83 | try |
| 84 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 85 | unflatten(pel); |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 86 | validate(); |
| 87 | } |
| 88 | catch (const std::exception& e) |
| 89 | { |
| 90 | log<level::ERR>("Cannot unflatten user header", |
| 91 | entry("ERROR=%s", e.what())); |
| 92 | _valid = false; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | void UserHeader::validate() |
| 97 | { |
| 98 | bool failed = false; |
Matt Spinler | 1a94cc3 | 2019-09-11 13:32:12 -0500 | [diff] [blame] | 99 | if (header().id != static_cast<uint16_t>(SectionID::userHeader)) |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 100 | { |
| 101 | log<level::ERR>("Invalid user header section ID", |
| 102 | entry("ID=0x%X", header().id)); |
| 103 | failed = true; |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | if (header().version != userHeaderVersion) |
| 107 | { |
| 108 | log<level::ERR>("Invalid user header version", |
| 109 | entry("VERSION=0x%X", header().version)); |
| 110 | failed = true; |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | _valid = (failed) ? false : true; |
| 114 | } |
| 115 | |
| 116 | } // namespace pels |
| 117 | } // namespace openpower |