blob: 626955fed6c1c126595bd76cd09a620e5f0abe68 [file] [log] [blame]
Alexander Hansen40fb5492025-10-28 17:56:12 +01001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright 2019 IBM Corporation
3
Matt Spinler09d64002019-09-11 14:29:46 -05004#include "failing_mtms.hpp"
5
Harisuddin Mohamed Isae2d1bf32020-02-06 17:32:38 +08006#include "json_utils.hpp"
Matt Spinler09d64002019-09-11 14:29:46 -05007#include "pel_types.hpp"
Harisuddin Mohamed Isabebeb942020-03-12 17:12:24 +08008#include "pel_values.hpp"
Matt Spinler09d64002019-09-11 14:29:46 -05009
Arya K Padman5bc26532024-04-10 06:19:25 -050010#include <phosphor-logging/lg2.hpp>
Matt Spinler09d64002019-09-11 14:29:46 -050011
12namespace openpower
13{
14namespace pels
15{
16
Harisuddin Mohamed Isabebeb942020-03-12 17:12:24 +080017namespace pv = openpower::pels::pel_values;
Arya K Padman5bc26532024-04-10 06:19:25 -050018
Matt Spinler09d64002019-09-11 14:29:46 -050019static constexpr uint8_t failingMTMSVersion = 0x01;
20
21FailingMTMS::FailingMTMS(const DataInterfaceBase& dataIface) :
22 _mtms(dataIface.getMachineTypeModel(), dataIface.getMachineSerialNumber())
23{
24 _header.id = static_cast<uint16_t>(SectionID::failingMTMS);
25 _header.size = FailingMTMS::flattenedSize();
26 _header.version = failingMTMSVersion;
27 _header.subType = 0;
28 _header.componentID = static_cast<uint16_t>(ComponentID::phosphorLogging);
Matt Spinleraa659472019-10-23 09:26:48 -050029
30 _valid = true;
Matt Spinler09d64002019-09-11 14:29:46 -050031}
32
33FailingMTMS::FailingMTMS(Stream& pel)
34{
35 try
36 {
37 unflatten(pel);
38 validate();
39 }
Patrick Williams66491c62021-10-06 12:23:37 -050040 catch (const std::exception& e)
Matt Spinler09d64002019-09-11 14:29:46 -050041 {
Arya K Padman5bc26532024-04-10 06:19:25 -050042 lg2::error("Cannot unflatten failing MTM section: {EXCEPTION}",
43 "EXCEPTION", e);
Matt Spinler09d64002019-09-11 14:29:46 -050044 _valid = false;
45 }
46}
47
48void FailingMTMS::validate()
49{
50 bool failed = false;
51
52 if (header().id != static_cast<uint16_t>(SectionID::failingMTMS))
53 {
Arya K Padman5bc26532024-04-10 06:19:25 -050054 lg2::error("Invalid failing MTMS section ID: {HEADER_ID}", "HEADER_ID",
55 lg2::hex, header().id);
Matt Spinler09d64002019-09-11 14:29:46 -050056 failed = true;
57 }
58
59 if (header().version != failingMTMSVersion)
60 {
Arya K Padman5bc26532024-04-10 06:19:25 -050061 lg2::error("Invalid failing MTMS version: {HEADER_VERSION}",
62 "HEADER_VERSION", lg2::hex, header().version);
Matt Spinler09d64002019-09-11 14:29:46 -050063 failed = true;
64 }
65
66 _valid = (failed) ? false : true;
67}
68
Matt Spinler06885452019-11-06 10:35:42 -060069void FailingMTMS::flatten(Stream& stream) const
Matt Spinler09d64002019-09-11 14:29:46 -050070{
71 stream << _header << _mtms;
72}
73
74void FailingMTMS::unflatten(Stream& stream)
75{
76 stream >> _header >> _mtms;
77}
78
Matt Spinlerb832aa52023-03-21 15:32:34 -050079std::optional<std::string> FailingMTMS::getJSON(uint8_t creatorID) const
Harisuddin Mohamed Isae2d1bf32020-02-06 17:32:38 +080080{
81 std::string json;
Harisuddin Mohamed Isabebeb942020-03-12 17:12:24 +080082 jsonInsert(json, pv::sectionVer, getNumberString("%d", _header.version), 1);
83 jsonInsert(json, pv::subSection, getNumberString("%d", _header.subType), 1);
84 jsonInsert(json, pv::createdBy,
Matt Spinlerb832aa52023-03-21 15:32:34 -050085 getComponentName(_header.componentID, creatorID), 1);
Harisuddin Mohamed Isae2d1bf32020-02-06 17:32:38 +080086 jsonInsert(json, "Machine Type Model", _mtms.machineTypeAndModel(), 1);
87 jsonInsert(json, "Serial Number", trimEnd(_mtms.machineSerialNumber()), 1);
88 json.erase(json.size() - 2);
89 return json;
90}
Matt Spinler09d64002019-09-11 14:29:46 -050091} // namespace pels
92} // namespace openpower