blob: acac0f5b2b009c515e5a8cc6c838c2b14507cf96 [file] [log] [blame]
Matt Spinler711d51d2019-11-06 09:36:51 -06001/**
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 Spinler8c686cc2019-09-20 13:46:02 -050016#include "severity.hpp"
17
18namespace openpower
19{
20namespace pels
21{
22
23using LogSeverity = phosphor::logging::Entry::Level;
24
Matt Spinler8b81ec02022-07-12 13:25:37 -050025namespace
26{
27
28LogSeverity convertPELSeverityToOBMC(SeverityType pelSeverity)
29{
30 LogSeverity logSeverity = LogSeverity::Error;
31
32 const std::map<SeverityType, LogSeverity> severities{
33 {SeverityType::nonError, LogSeverity::Informational},
34 {SeverityType::recovered, LogSeverity::Informational},
35 {SeverityType::predictive, LogSeverity::Warning},
36 {SeverityType::unrecoverable, LogSeverity::Error},
37 {SeverityType::critical, LogSeverity::Critical},
38 {SeverityType::diagnostic, LogSeverity::Error},
39 {SeverityType::symptom, LogSeverity::Warning}};
40
41 auto s = severities.find(pelSeverity);
42 if (s != severities.end())
43 {
44 logSeverity = s->second;
45 }
46
47 return logSeverity;
48}
49
50} // namespace
51
Matt Spinler8c686cc2019-09-20 13:46:02 -050052uint8_t convertOBMCSeverityToPEL(LogSeverity severity)
53{
Matt Spinlera7525aa2019-11-01 11:11:07 -050054 uint8_t pelSeverity = static_cast<uint8_t>(SeverityType::unrecoverable);
Matt Spinler8c686cc2019-09-20 13:46:02 -050055 switch (severity)
56 {
57 case (LogSeverity::Notice):
58 case (LogSeverity::Informational):
59 case (LogSeverity::Debug):
Matt Spinlera7525aa2019-11-01 11:11:07 -050060 pelSeverity = static_cast<uint8_t>(SeverityType::nonError);
Matt Spinler8c686cc2019-09-20 13:46:02 -050061 break;
62
63 case (LogSeverity::Warning):
Matt Spinlera7525aa2019-11-01 11:11:07 -050064 pelSeverity = static_cast<uint8_t>(SeverityType::predictive);
Matt Spinler8c686cc2019-09-20 13:46:02 -050065 break;
66
67 case (LogSeverity::Critical):
Matt Spinlera7525aa2019-11-01 11:11:07 -050068 pelSeverity = static_cast<uint8_t>(SeverityType::critical);
Matt Spinler8c686cc2019-09-20 13:46:02 -050069 break;
70
71 case (LogSeverity::Emergency):
72 case (LogSeverity::Alert):
73 case (LogSeverity::Error):
Matt Spinlera7525aa2019-11-01 11:11:07 -050074 pelSeverity = static_cast<uint8_t>(SeverityType::unrecoverable);
Matt Spinler8c686cc2019-09-20 13:46:02 -050075 break;
76 }
77
78 return pelSeverity;
79}
Matt Spinler8b81ec02022-07-12 13:25:37 -050080
81std::optional<LogSeverity> fixupLogSeverity(LogSeverity obmcSeverity,
82 SeverityType pelSeverity)
83{
84 bool isNonErrPelSev = (pelSeverity == SeverityType::nonError) ||
85 (pelSeverity == SeverityType::recovered);
86
87 bool isNonErrObmcSev = (obmcSeverity == LogSeverity::Notice) ||
88 (obmcSeverity == LogSeverity::Informational) ||
89 (obmcSeverity == LogSeverity::Debug);
90
91 // If a nonError/recovered PEL, then the LogSeverity must be
92 // Notice/Informational/Debug, otherwise set it to Informational.
93 if (isNonErrPelSev && !isNonErrObmcSev)
94 {
95 return LogSeverity::Informational;
96 }
97
98 // If a Notice/Informational/Debug LogSeverity, then the PEL
99 // severity must be nonError/recovered, otherwise set it
100 // to an appropriate value based on the actual PEL severity.
101 if (isNonErrObmcSev && !isNonErrPelSev)
102 {
103 return convertPELSeverityToOBMC(pelSeverity);
104 }
105
106 // If PEL is critical, the LogSeverity should be as well.
107 if ((obmcSeverity != LogSeverity::Critical) &&
108 (pelSeverity == SeverityType::critical))
109 {
110 return LogSeverity::Critical;
111 }
112
113 return std::nullopt;
114}
115
Matt Spinler8c686cc2019-09-20 13:46:02 -0500116} // namespace pels
117} // namespace openpower