Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 1 | #include "pel.hpp" |
| 2 | |
| 3 | #include "bcd_time.hpp" |
Matt Spinler | aa65947 | 2019-10-23 09:26:48 -0500 | [diff] [blame^] | 4 | #include "failing_mtms.hpp" |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 5 | #include "log_id.hpp" |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 6 | #include "section_factory.hpp" |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 7 | #include "src.hpp" |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 8 | #include "stream.hpp" |
| 9 | |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 10 | #include <phosphor-logging/log.hpp> |
| 11 | |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 12 | namespace openpower |
| 13 | { |
| 14 | namespace pels |
| 15 | { |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 16 | namespace message = openpower::pels::message; |
| 17 | |
| 18 | PEL::PEL(const message::Entry& entry, uint32_t obmcLogID, uint64_t timestamp, |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 19 | phosphor::logging::Entry::Level severity, |
Matt Spinler | aa65947 | 2019-10-23 09:26:48 -0500 | [diff] [blame^] | 20 | const AdditionalData& additionalData, |
| 21 | const DataInterfaceBase& dataIface) |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 22 | { |
| 23 | _ph = std::make_unique<PrivateHeader>(entry.componentID, obmcLogID, |
| 24 | timestamp); |
| 25 | _uh = std::make_unique<UserHeader>(entry, severity); |
| 26 | |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 27 | auto src = std::make_unique<SRC>(entry, additionalData); |
| 28 | _optionalSections.push_back(std::move(src)); |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 29 | |
Matt Spinler | aa65947 | 2019-10-23 09:26:48 -0500 | [diff] [blame^] | 30 | auto mtms = std::make_unique<FailingMTMS>(dataIface); |
| 31 | _optionalSections.push_back(std::move(mtms)); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 32 | |
| 33 | _ph->sectionCount() = 2 + _optionalSections.size(); |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 34 | } |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 35 | |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 36 | PEL::PEL(std::vector<uint8_t>& data) : PEL(data, 0) |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 37 | { |
| 38 | } |
| 39 | |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 40 | PEL::PEL(std::vector<uint8_t>& data, uint32_t obmcLogID) |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 41 | { |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 42 | populateFromRawData(data, obmcLogID); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 43 | } |
| 44 | |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 45 | void PEL::populateFromRawData(std::vector<uint8_t>& data, uint32_t obmcLogID) |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 46 | { |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 47 | Stream pelData{data}; |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 48 | _ph = std::make_unique<PrivateHeader>(pelData); |
| 49 | if (obmcLogID != 0) |
| 50 | { |
| 51 | _ph->obmcLogID() = obmcLogID; |
| 52 | } |
| 53 | |
| 54 | _uh = std::make_unique<UserHeader>(pelData); |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 55 | |
| 56 | // Use the section factory to create the rest of the objects |
| 57 | for (size_t i = 2; i < _ph->sectionCount(); i++) |
| 58 | { |
| 59 | auto section = section_factory::create(pelData); |
| 60 | _optionalSections.push_back(std::move(section)); |
| 61 | } |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | bool PEL::valid() const |
| 65 | { |
| 66 | bool valid = _ph->valid(); |
| 67 | |
| 68 | if (valid) |
| 69 | { |
| 70 | valid = _uh->valid(); |
| 71 | } |
| 72 | |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 73 | if (valid) |
| 74 | { |
| 75 | if (!std::all_of(_optionalSections.begin(), _optionalSections.end(), |
| 76 | [](const auto& section) { return section->valid(); })) |
| 77 | { |
| 78 | valid = false; |
| 79 | } |
| 80 | } |
| 81 | |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 82 | return valid; |
| 83 | } |
| 84 | |
| 85 | void PEL::setCommitTime() |
| 86 | { |
| 87 | auto now = std::chrono::system_clock::now(); |
| 88 | _ph->commitTimestamp() = getBCDTime(now); |
| 89 | } |
| 90 | |
| 91 | void PEL::assignID() |
| 92 | { |
| 93 | _ph->id() = generatePELID(); |
| 94 | } |
| 95 | |
| 96 | void PEL::flatten(std::vector<uint8_t>& pelBuffer) |
| 97 | { |
| 98 | Stream pelData{pelBuffer}; |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 99 | |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 100 | if (!valid()) |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 101 | { |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 102 | using namespace phosphor::logging; |
| 103 | log<level::WARNING>("Unflattening an invalid PEL"); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 104 | } |
| 105 | |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 106 | _ph->flatten(pelData); |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 107 | _uh->flatten(pelData); |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 108 | |
| 109 | for (auto& section : _optionalSections) |
| 110 | { |
| 111 | section->flatten(pelData); |
| 112 | } |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | std::vector<uint8_t> PEL::data() |
| 116 | { |
Matt Spinler | 07eefc5 | 2019-09-26 11:18:26 -0500 | [diff] [blame] | 117 | std::vector<uint8_t> pelData; |
| 118 | flatten(pelData); |
| 119 | return pelData; |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 120 | } |
| 121 | |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 122 | std::optional<SRC*> PEL::primarySRC() const |
| 123 | { |
| 124 | auto src = std::find_if( |
| 125 | _optionalSections.begin(), _optionalSections.end(), [](auto& section) { |
| 126 | return section->header().id == |
| 127 | static_cast<uint16_t>(SectionID::primarySRC); |
| 128 | }); |
| 129 | if (src != _optionalSections.end()) |
| 130 | { |
| 131 | return static_cast<SRC*>(src->get()); |
| 132 | } |
| 133 | |
| 134 | return std::nullopt; |
| 135 | } |
| 136 | |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 137 | } // namespace pels |
| 138 | } // namespace openpower |