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