1 #include "pel_rules.hpp"
2 
3 #include "pel_types.hpp"
4 
5 #include <bitset>
6 
7 namespace openpower
8 {
9 namespace pels
10 {
11 namespace pel_rules
12 {
13 
14 std::tuple<uint16_t, uint8_t> check(uint16_t actionFlags, uint8_t eventType,
15                                     uint8_t severity)
16 {
17     std::bitset<16> newActionFlags{actionFlags};
18     uint8_t newEventType = eventType;
19     auto sevType = static_cast<SeverityType>(severity & 0xF0);
20 
21     // Always report, unless specifically told not to
22     if (!newActionFlags.test(dontReportToHostFlagBit))
23     {
24         newActionFlags.set(reportFlagBit);
25     }
26     else
27     {
28         newActionFlags.reset(reportFlagBit);
29     }
30 
31     // Call home by BMC not supported
32     newActionFlags.reset(spCallHomeFlagBit);
33 
34     switch (sevType)
35     {
36         case SeverityType::nonError:
37         {
38             // Informational errors never need service actions or call home.
39             newActionFlags.reset(serviceActionFlagBit);
40             newActionFlags.reset(callHomeFlagBit);
41 
42             // Ensure event type isn't 'not applicable'
43             if (newEventType == static_cast<uint8_t>(EventType::notApplicable))
44             {
45                 newEventType =
46                     static_cast<uint8_t>(EventType::miscInformational);
47             }
48 
49             // The misc info and tracing event types are always hidden.
50             // For other event types, it's up to the creator.
51             if ((newEventType ==
52                  static_cast<uint8_t>(EventType::miscInformational)) ||
53                 (newEventType == static_cast<uint8_t>(EventType::tracing)))
54             {
55                 newActionFlags.set(hiddenFlagBit);
56             }
57             break;
58         }
59         case SeverityType::recovered:
60         {
61             // Recovered errors are hidden, and by definition need no
62             // service action or call home.
63             newActionFlags.set(hiddenFlagBit);
64             newActionFlags.reset(serviceActionFlagBit);
65             newActionFlags.reset(callHomeFlagBit);
66             break;
67         }
68         case SeverityType::predictive:
69         case SeverityType::unrecoverable:
70         case SeverityType::critical:
71         case SeverityType::diagnostic:
72         case SeverityType::symptom:
73         {
74             // Report these others as normal errors.
75             newActionFlags.reset(hiddenFlagBit);
76             newActionFlags.set(serviceActionFlagBit);
77             newActionFlags.set(callHomeFlagBit);
78             break;
79         }
80     }
81 
82     return {static_cast<uint16_t>(newActionFlags.to_ulong()), newEventType};
83 }
84 
85 } // namespace pel_rules
86 } // namespace pels
87 } // namespace openpower
88