blob: 2871da65dda1653ed7ed10c885e7f50f451da2c5 [file] [log] [blame]
Zane Shelleyd3b9bac2020-11-17 21:59:12 -06001#include <unistd.h>
2
3#include <hei_main.hpp>
4#include <phosphor-logging/elog.hpp>
5#include <sdbusplus/bus.hpp>
6#include <util/ffdc_file.hpp>
7#include <util/pdbg.hpp>
8#include <util/trace.hpp>
9#include <xyz/openbmc_project/Logging/Create/server.hpp>
10#include <xyz/openbmc_project/Logging/Entry/server.hpp>
11
12namespace LogSvr = sdbusplus::xyz::openbmc_project::Logging::server;
13
14namespace analyzer
15{
16
17bool __isCheckstop(const libhei::IsolationData& i_isoData)
18{
19 // Look for any signature with a system checkstop attention.
20 auto list = i_isoData.getSignatureList();
21 auto itr = std::find_if(list.begin(), list.end(), [](const auto& s) {
22 return libhei::ATTN_TYPE_CHECKSTOP == s.getAttnType();
23 });
24
25 return list.end() != itr;
26}
27
28//------------------------------------------------------------------------------
29
30void __setSrc(const libhei::Signature& i_rootCause,
31 std::map<std::string, std::string>& io_logData)
32{
33 // [ 0:15] chip model
34 // [16:23] reserved space in chip ID
35 // [24:31] chip EC level
36 uint32_t word6 = i_rootCause.getChip().getType();
37
38 // [ 0:15] chip position
39 // [16:23] unused
40 // [24:31] signature attention type
41 auto pos = util::pdbg::getChipPos(i_rootCause.getChip());
42 auto attn = i_rootCause.getAttnType();
43
44 uint32_t word7 = (pos & 0xffff) << 16 | (attn & 0xff);
45
46 // [ 0:15] signature ID
47 // [16:23] signature instance
48 // [24:31] signature bit position
49 uint32_t word8 = i_rootCause.toUint32();
50
51 // Word 9 is currently unused
52
53 io_logData["SRC6"] = std::to_string(word6);
54 io_logData["SRC7"] = std::to_string(word7);
55 io_logData["SRC8"] = std::to_string(word8);
56}
57
58//------------------------------------------------------------------------------
59
60void __captureSignatureList(const libhei::IsolationData& i_isoData,
61 std::vector<util::FFDCFile>& io_userDataFiles)
62{
63 // TODO: Create a user data section that contains the complete list of
64 // signatures found during isolation.
65}
66
67//------------------------------------------------------------------------------
68
69std::string __getMessageRegistry(bool i_isCheckstop)
70{
71 // For now, there are only two choices:
72 return i_isCheckstop ? "org.open_power.HwDiags.Error.Checkstop"
73 : "org.open_power.HwDiags.Error.Predictive";
74}
75
76//------------------------------------------------------------------------------
77
78std::string __getMessageSeverity(bool i_isCheckstop)
79{
80 // We could specify the PEL severity in the message registry entry. However,
81 // that would require multiple copies of each entry for each possible
82 // severity. As a workaround, we will not explicitly state the PEL severity
83 // in the message registry. Instead, the message severity will be converted
84 // into a PEL severity via the openpower-pels extention of phosphor-logging.
85
86 // Initially, we'll use a severity that will generate a predictive PEL. This
87 // is intended for Terminate Immediate (TI) errors and will require service.
88 LogSvr::Entry::Level severity = LogSvr::Entry::Level::Warning;
89
90 // If the reason for analysis was due to a system checsktop, the severity
91 // will be upgraded to a unrecoverable PEL.
92 if (i_isCheckstop)
93 severity = LogSvr::Entry::Level::Error;
94
95 // Convert the message severity to a string.
96 return LogSvr::Entry::convertLevelToString(severity);
97}
98
99//------------------------------------------------------------------------------
100
101void createPel(const libhei::Signature& i_rootCause,
102 const libhei::IsolationData& i_isoData)
103{
104 // The message registry will require additional log data to fill in keywords
105 // and additional log data.
106 std::map<std::string, std::string> logData;
107
108 // Keep track of the temporary files associated with the user data FFDC.
109 // WARNING: Once the objects stored in this vector go out of scope, the
110 // temporary files will be deleted. So they must remain in scope
111 // until the PEL is submitted.
112 std::vector<util::FFDCFile> userDataFiles;
113
114 // In several cases, it is important to know if the reason for analysis was
115 // due to a system checsktop.
116 bool isCheckstop = __isCheckstop(i_isoData);
117
118 // Set words 6-9 of the SRC.
119 __setSrc(i_rootCause, logData);
120
121 // Capture the complete signature list.
122 __captureSignatureList(i_isoData, userDataFiles);
123
124 // Now, that all of the user data files have been created, transform the
125 // data into the proper format for the PEL.
126 std::vector<util::FFDCTuple> userData;
127 util::transformFFDC(userDataFiles, userData);
128
129 // Get access to logging interface and method for creating log.
130 auto bus = sdbusplus::bus::new_default_system();
131
132 // Using direct create method (for additional data).
133 auto method = bus.new_method_call(
134 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
135 "xyz.openbmc_project.Logging.Create", "CreateWithFFDCFiles");
136
137 // The "Create" method requires manually adding the process ID.
138 logData["_PID"] = std::to_string(getpid());
139
140 // Get the message registry entry for this failure.
141 auto message = __getMessageRegistry(isCheckstop);
142
143 // Get the message severity for this failure.
144 auto severity = __getMessageSeverity(isCheckstop);
145
146 // Add the message, with additional log and user data.
147 method.append(message, severity, logData, userData);
148
149 // Log the event.
150 bus.call_noreply(method);
151}
152
153} // namespace analyzer