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 | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 16 | #include "failing_mtms.hpp" |
| 17 | |
Harisuddin Mohamed Isa | e2d1bf3 | 2020-02-06 17:32:38 +0800 | [diff] [blame] | 18 | #include "json_utils.hpp" |
Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 19 | #include "pel_types.hpp" |
Harisuddin Mohamed Isa | bebeb94 | 2020-03-12 17:12:24 +0800 | [diff] [blame] | 20 | #include "pel_values.hpp" |
Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 21 | |
Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame^] | 22 | #include <phosphor-logging/lg2.hpp> |
Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 23 | |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 24 | #include <format> |
| 25 | |
Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 26 | namespace openpower |
| 27 | { |
| 28 | namespace pels |
| 29 | { |
| 30 | |
Harisuddin Mohamed Isa | bebeb94 | 2020-03-12 17:12:24 +0800 | [diff] [blame] | 31 | namespace pv = openpower::pels::pel_values; |
Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame^] | 32 | |
Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 33 | static constexpr uint8_t failingMTMSVersion = 0x01; |
| 34 | |
| 35 | FailingMTMS::FailingMTMS(const DataInterfaceBase& dataIface) : |
| 36 | _mtms(dataIface.getMachineTypeModel(), dataIface.getMachineSerialNumber()) |
| 37 | { |
| 38 | _header.id = static_cast<uint16_t>(SectionID::failingMTMS); |
| 39 | _header.size = FailingMTMS::flattenedSize(); |
| 40 | _header.version = failingMTMSVersion; |
| 41 | _header.subType = 0; |
| 42 | _header.componentID = static_cast<uint16_t>(ComponentID::phosphorLogging); |
Matt Spinler | aa65947 | 2019-10-23 09:26:48 -0500 | [diff] [blame] | 43 | |
| 44 | _valid = true; |
Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | FailingMTMS::FailingMTMS(Stream& pel) |
| 48 | { |
| 49 | try |
| 50 | { |
| 51 | unflatten(pel); |
| 52 | validate(); |
| 53 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 54 | catch (const std::exception& e) |
Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 55 | { |
Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame^] | 56 | lg2::error("Cannot unflatten failing MTM section: {EXCEPTION}", |
| 57 | "EXCEPTION", e); |
Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 58 | _valid = false; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void FailingMTMS::validate() |
| 63 | { |
| 64 | bool failed = false; |
| 65 | |
| 66 | if (header().id != static_cast<uint16_t>(SectionID::failingMTMS)) |
| 67 | { |
Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame^] | 68 | lg2::error("Invalid failing MTMS section ID: {HEADER_ID}", "HEADER_ID", |
| 69 | lg2::hex, header().id); |
Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 70 | failed = true; |
| 71 | } |
| 72 | |
| 73 | if (header().version != failingMTMSVersion) |
| 74 | { |
Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame^] | 75 | lg2::error("Invalid failing MTMS version: {HEADER_VERSION}", |
| 76 | "HEADER_VERSION", lg2::hex, header().version); |
Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 77 | failed = true; |
| 78 | } |
| 79 | |
| 80 | _valid = (failed) ? false : true; |
| 81 | } |
| 82 | |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 83 | void FailingMTMS::flatten(Stream& stream) const |
Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 84 | { |
| 85 | stream << _header << _mtms; |
| 86 | } |
| 87 | |
| 88 | void FailingMTMS::unflatten(Stream& stream) |
| 89 | { |
| 90 | stream >> _header >> _mtms; |
| 91 | } |
| 92 | |
Matt Spinler | b832aa5 | 2023-03-21 15:32:34 -0500 | [diff] [blame] | 93 | std::optional<std::string> FailingMTMS::getJSON(uint8_t creatorID) const |
Harisuddin Mohamed Isa | e2d1bf3 | 2020-02-06 17:32:38 +0800 | [diff] [blame] | 94 | { |
| 95 | std::string json; |
Harisuddin Mohamed Isa | bebeb94 | 2020-03-12 17:12:24 +0800 | [diff] [blame] | 96 | jsonInsert(json, pv::sectionVer, getNumberString("%d", _header.version), 1); |
| 97 | jsonInsert(json, pv::subSection, getNumberString("%d", _header.subType), 1); |
| 98 | jsonInsert(json, pv::createdBy, |
Matt Spinler | b832aa5 | 2023-03-21 15:32:34 -0500 | [diff] [blame] | 99 | getComponentName(_header.componentID, creatorID), 1); |
Harisuddin Mohamed Isa | e2d1bf3 | 2020-02-06 17:32:38 +0800 | [diff] [blame] | 100 | jsonInsert(json, "Machine Type Model", _mtms.machineTypeAndModel(), 1); |
| 101 | jsonInsert(json, "Serial Number", trimEnd(_mtms.machineSerialNumber()), 1); |
| 102 | json.erase(json.size() - 2); |
| 103 | return json; |
| 104 | } |
Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 105 | } // namespace pels |
| 106 | } // namespace openpower |