blob: 77b1df7285293334d148cb5146aa84652732a597 [file] [log] [blame]
Ben Tynerbcf65a82020-12-01 08:46:36 -06001#include <attn/attn_common.hpp>
Ben Tynerb797b3e2020-06-29 10:12:05 -05002#include <attn/attn_handler.hpp>
3#include <attn/attn_logging.hpp>
Ben Tynerf5210bb2021-01-05 12:58:10 -06004#include <attn/pel/pel_common.hpp>
Ben Tynerb797b3e2020-06-29 10:12:05 -05005#include <attn/ti_handler.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06006#include <sdbusplus/bus.hpp>
Ben Tynerff17f962020-09-23 08:21:19 -05007#include <sdbusplus/exception.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06008
Ben Tyner40717722020-09-23 09:43:20 -05009#include <iomanip>
10#include <iostream>
11
Ben Tyner9ae5ca42020-02-28 13:13:50 -060012namespace attn
13{
14
Ben Tyner8c5e4f42020-10-28 11:11:55 -050015/**
16 * @brief Determine if this is a HB or PHYP TI event
17 *
18 * Use the TI info data area to determine if this is either a HB or a PHYP
19 * TI event then handle the event.
20 *
Ben Tynerf5210bb2021-01-05 12:58:10 -060021 * @param i_tiDataArea pointer to the TI info data
Ben Tyner8c5e4f42020-10-28 11:11:55 -050022 */
Ben Tyner792f32f2020-06-02 08:50:47 -050023int tiHandler(TiDataArea* i_tiDataArea)
Ben Tyner9ae5ca42020-02-28 13:13:50 -060024{
Ben Tynere4f5dbe2020-10-19 07:19:33 -050025 int rc = RC_SUCCESS;
Ben Tyner9ae5ca42020-02-28 13:13:50 -060026
Ben Tyner8c5e4f42020-10-28 11:11:55 -050027 // check TI data area if it is available
Ben Tynere4f5dbe2020-10-19 07:19:33 -050028 if (nullptr != i_tiDataArea)
Ben Tyner792f32f2020-06-02 08:50:47 -050029 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050030 // HB v. PHYP TI logic: Only hosboot will fill in hbTerminateType
Ben Tyner8882c322021-02-05 12:13:21 -060031 // and it will be non-zero. Only hostboot will fill out source and
32 // it it will be non-zero. Only PHYP will fill in srcFormat and it
33 // will be non-zero.
Ben Tyner8c5e4f42020-10-28 11:11:55 -050034 if ((0 == i_tiDataArea->hbTerminateType) &&
35 (0 == i_tiDataArea->source) && (0 != i_tiDataArea->srcFormat))
Ben Tynere4f5dbe2020-10-19 07:19:33 -050036 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050037 handlePhypTi(i_tiDataArea);
Ben Tynere4f5dbe2020-10-19 07:19:33 -050038 }
39 else
40 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050041 handleHbTi(i_tiDataArea);
Ben Tynere4f5dbe2020-10-19 07:19:33 -050042 }
Ben Tyner8c5e4f42020-10-28 11:11:55 -050043 }
44 else
45 {
46 // TI data was not available, assume PHYP TI for now. When a host state
47 // management interface becomes availabe we may be able to make a more
48 // informed decision here.
49 handlePhypTi(i_tiDataArea);
Ben Tynere4f5dbe2020-10-19 07:19:33 -050050 }
Ben Tyner40717722020-09-23 09:43:20 -050051
Ben Tyner8c5e4f42020-10-28 11:11:55 -050052 return rc;
53}
Ben Tynere4f5dbe2020-10-19 07:19:33 -050054
Ben Tyner8c5e4f42020-10-28 11:11:55 -050055/**
Ben Tyner8c5e4f42020-10-28 11:11:55 -050056 * @brief Handle a PHYP terminate immediate special attention
57 *
58 * The TI info data area will contain information pertaining to the TI
59 * condition. We will wither quiesce the host or initiate a MPIPL depending
60 * depending on the auto reboot configuration. We will also create a PEL which
61 * will contain the TI info data and FFDC data captured in the system journal.
62 *
63 * @param i_tiDataArea pointer to TI information filled in by hostboot
64 */
65void handlePhypTi(TiDataArea* i_tiDataArea)
66{
67 trace<level::INFO>("PHYP TI");
68
69 if (autoRebootEnabled())
70 {
Ben Tynerfe2757b2021-01-14 13:17:50 -060071 // If autoreboot is enabled we will start crash (mpipl) mode target
72 transitionHost(HostState::Crash);
Ben Tyner792f32f2020-06-02 08:50:47 -050073 }
Ben Tyner40717722020-09-23 09:43:20 -050074 else
75 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050076 // If autoreboot is disabled we will quiesce the host
Ben Tynerbcf65a82020-12-01 08:46:36 -060077 transitionHost(HostState::Quiesce);
Ben Tyner40717722020-09-23 09:43:20 -050078 }
Ben Tyner792f32f2020-06-02 08:50:47 -050079
Ben Tyner8c5e4f42020-10-28 11:11:55 -050080 // gather additional data for PEL
81 std::map<std::string, std::string> tiAdditionalData;
Ben Tynere4f5dbe2020-10-19 07:19:33 -050082
Ben Tyner8c5e4f42020-10-28 11:11:55 -050083 if (nullptr != i_tiDataArea)
84 {
85 parsePhypOpalTiInfo(tiAdditionalData, i_tiDataArea);
Ben Tyner8c5e4f42020-10-28 11:11:55 -050086 }
87
Ben Tynerf5210bb2021-01-05 12:58:10 -060088 tiAdditionalData["Subsystem"] =
89 std::to_string(static_cast<uint8_t>(pel::SubsystemID::hypervisor));
90
Ben Tynera33b2ab2021-02-05 12:27:19 -060091 // copy ascii src chars to additional data
92 char srcChar[9]; // 8 char src + null term
Ben Tynerf5210bb2021-01-05 12:58:10 -060093 memcpy(srcChar, &(i_tiDataArea->asciiData0), 4);
94 memcpy(&srcChar[4], &(i_tiDataArea->asciiData1), 4);
Ben Tynera33b2ab2021-02-05 12:27:19 -060095 srcChar[8] = 0;
Ben Tynerf5210bb2021-01-05 12:58:10 -060096 tiAdditionalData["SrcAscii"] = std::string{srcChar};
97
98 eventTerminate(tiAdditionalData, (char*)i_tiDataArea);
Ben Tyner8c5e4f42020-10-28 11:11:55 -050099}
100
101/**
102 * @brief Handle a hostboot terminate immediate special attention
103 *
104 * The TI info data area will contain information pertaining to the TI
105 * condition. The course of action to take regarding the host state will
106 * depend on the contents of the TI info data area. We will also create a
107 * PEL containing the TI info data and FFDC data captured in the system
108 * journal.
109 *
110 * @param i_tiDataArea pointer to TI information filled in by hostboot
111 */
112void handleHbTi(TiDataArea* i_tiDataArea)
113{
114 trace<level::INFO>("HB TI");
115
116 bool hbDumpRequested = true; // HB dump is common case
117 bool generatePel = true; // assume PEL will be created
118 bool terminateHost = true; // transition host state
119
120 // handle specific hostboot reason codes
121 if (nullptr != i_tiDataArea)
122 {
Ben Tyner8882c322021-02-05 12:13:21 -0600123 std::stringstream ss; // stream object for tracing
124 std::string strobj; // string object for tracing
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500125
126 switch (i_tiDataArea->hbTerminateType)
127 {
128 case TI_WITH_PLID:
129 case TI_WITH_EID:
Ben Tyner8882c322021-02-05 12:13:21 -0600130
131 // trace this value
132 ss.str(std::string()); // empty the stream
133 ss.clear(); // clear the stream
134 ss << "TI with PLID/EID: " << std::hex << std::showbase
135 << std::setw(8) << std::setfill('0')
136 << be32toh(i_tiDataArea->asciiData1);
137 strobj = ss.str();
138 trace<level::INFO>(strobj.c_str());
139
140 // see if HB dump is requested
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500141 if (0 == i_tiDataArea->hbDumpFlag)
142 {
143 hbDumpRequested = false; // no HB dump requested
144 }
145 break;
146 case TI_WITH_SRC:
Ben Tyner8882c322021-02-05 12:13:21 -0600147 // Reason code is byte 2 and 3 of 4 byte srcWord12HbWord0
148 uint16_t reasonCode = be32toh(i_tiDataArea->srcWord12HbWord0);
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500149
Ben Tyner8882c322021-02-05 12:13:21 -0600150 // trace this value
151 ss.str(std::string()); // empty the stream
152 ss.clear(); // clear the stream
153 ss << "TI with SRC: " << std::hex << std::showbase
154 << std::setw(4) << std::setfill('0') << (int)reasonCode;
155 strobj = ss.str();
156 trace<level::INFO>(strobj.c_str());
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500157
Ben Tyner8882c322021-02-05 12:13:21 -0600158 switch (reasonCode)
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500159 {
160 case HB_SRC_SHUTDOWN_REQUEST:
161 trace<level::INFO>("shutdown request");
Ben Tyner8882c322021-02-05 12:13:21 -0600162 generatePel = false;
163 hbDumpRequested = false;
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500164 break;
165 case HB_SRC_KEY_TRANSITION:
Ben Tyner8882c322021-02-05 12:13:21 -0600166 // Note: Should never see this so lets leave
167 // hbDumpRequested == true so we can figure out why
168 // we are here.
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500169 trace<level::INFO>("key transition");
170 terminateHost = false;
171 break;
172 case HB_SRC_INSUFFICIENT_HW:
173 trace<level::INFO>("insufficient hardware");
174 break;
175 case HB_SRC_TPM_FAIL:
176 trace<level::INFO>("TPM fail");
177 break;
178 case HB_SRC_ROM_VERIFY:
179 trace<level::INFO>("ROM verify");
180 break;
181 case HB_SRC_EXT_MISMATCH:
182 trace<level::INFO>("EXT mismatch");
183 break;
184 case HB_SRC_ECC_UE:
185 trace<level::INFO>("ECC UE");
186 break;
187 case HB_SRC_UNSUPPORTED_MODE:
188 trace<level::INFO>("unsupported mode");
189 break;
190 case HB_SRC_UNSUPPORTED_SFCRANGE:
191 trace<level::INFO>("unsupported SFC range");
192 break;
193 case HB_SRC_PARTITION_TABLE:
194 trace<level::INFO>("partition table invalid");
195 break;
196 case HB_SRC_UNSUPPORTED_HARDWARE:
197 trace<level::INFO>("unsupported hardware");
198 break;
199 case HB_SRC_PNOR_CORRUPTION:
200 trace<level::INFO>("PNOR corruption");
201 break;
202 default:
203 trace<level::INFO>("reason: other");
204 }
205
206 break;
207 }
208 }
209
210 if (true == terminateHost)
211 {
212 // if hostboot dump is requested initiate dump
213 if (hbDumpRequested)
214 {
215 // Until HB dump support available just quiesce the host - once
216 // dump support is available the dump component will transition
217 // (ipl/halt) the host.
Ben Tynerbcf65a82020-12-01 08:46:36 -0600218 transitionHost(HostState::Quiesce);
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500219 }
220 else
221 {
222 // Quiese the host - when the host is quiesced it will either
223 // "halt" or IPL depending on autoreboot setting.
Ben Tynerbcf65a82020-12-01 08:46:36 -0600224 transitionHost(HostState::Quiesce);
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500225 }
226 }
227
228 // gather additional data for PEL
229 std::map<std::string, std::string> tiAdditionalData;
230
231 if (nullptr != i_tiDataArea)
232 {
233 parseHbTiInfo(tiAdditionalData, i_tiDataArea);
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500234 }
235
236 if (true == generatePel)
237 {
Ben Tynerf5210bb2021-01-05 12:58:10 -0600238 tiAdditionalData["Subsystem"] =
239 std::to_string(static_cast<uint8_t>(pel::SubsystemID::hostboot));
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600240
Ben Tynerf5210bb2021-01-05 12:58:10 -0600241 char srcChar[8];
242 memcpy(srcChar, &(i_tiDataArea->srcWord12HbWord0), 4);
243 memcpy(&srcChar[4], &(i_tiDataArea->asciiData1), 4);
244 tiAdditionalData["SrcAscii"] = std::string{srcChar};
Ben Tyner40717722020-09-23 09:43:20 -0500245
Ben Tynerf5210bb2021-01-05 12:58:10 -0600246 eventTerminate(tiAdditionalData, (char*)i_tiDataArea);
Ben Tyner40717722020-09-23 09:43:20 -0500247 }
248}
249
250/** @brief Parse the TI info data area into map as PHYP/OPAL data */
251void parsePhypOpalTiInfo(std::map<std::string, std::string>& i_map,
252 TiDataArea* i_tiDataArea)
253{
Ben Tyner1c4b02e2020-11-09 14:00:29 -0600254 if (nullptr == i_tiDataArea)
255 {
256 return;
257 }
258
Ben Tyner40717722020-09-23 09:43:20 -0500259 std::stringstream ss;
260
261 ss << std::hex << std::showbase;
262 ss << "0x00 TI Area Valid:" << (int)i_tiDataArea->tiAreaValid << ":";
263 ss << "0x01 Command:" << (int)i_tiDataArea->command << ":";
264 ss << "0x02 Num. Data Bytes:" << be16toh(i_tiDataArea->numDataBytes) << ":";
265 ss << "0x04 Reserved:" << (int)i_tiDataArea->reserved1 << ":";
266 ss << "0x06 HWDump Type:" << be16toh(i_tiDataArea->hardwareDumpType) << ":";
267 ss << "0x08 SRC Format:" << (int)i_tiDataArea->srcFormat << ":";
268 ss << "0x09 SRC Flags:" << (int)i_tiDataArea->srcFlags << ":";
269 ss << "0x0a Num. ASCII Words:" << (int)i_tiDataArea->numAsciiWords << ":";
270 ss << "0x0b Num. Hex Words:" << (int)i_tiDataArea->numHexWords << ":";
271 ss << "0x0e Length of SRC:" << be16toh(i_tiDataArea->lenSrc) << ":";
272 ss << "0x10 SRC Word 12:" << be32toh(i_tiDataArea->srcWord12HbWord0) << ":";
273 ss << "0x14 SRC Word 13:" << be32toh(i_tiDataArea->srcWord13HbWord2) << ":";
274 ss << "0x18 SRC Word 14:" << be32toh(i_tiDataArea->srcWord14HbWord3) << ":";
275 ss << "0x1c SRC Word 15:" << be32toh(i_tiDataArea->srcWord15HbWord4) << ":";
276 ss << "0x20 SRC Word 16:" << be32toh(i_tiDataArea->srcWord16HbWord5) << ":";
277 ss << "0x24 SRC Word 17:" << be32toh(i_tiDataArea->srcWord17HbWord6) << ":";
278 ss << "0x28 SRC Word 18:" << be32toh(i_tiDataArea->srcWord18HbWord7) << ":";
279 ss << "0x2c SRC Word 19:" << be32toh(i_tiDataArea->srcWord19HbWord8) << ":";
280 ss << "0x30 ASCII Data:" << be32toh(i_tiDataArea->asciiData0) << ":";
281 ss << "0x34 ASCII Data:" << be32toh(i_tiDataArea->asciiData1) << ":";
282 ss << "0x38 ASCII Data:" << be32toh(i_tiDataArea->asciiData2) << ":";
283 ss << "0x3c ASCII Data:" << be32toh(i_tiDataArea->asciiData3) << ":";
284 ss << "0x40 ASCII Data:" << be32toh(i_tiDataArea->asciiData4) << ":";
285 ss << "0x44 ASCII Data:" << be32toh(i_tiDataArea->asciiData5) << ":";
286 ss << "0x48 ASCII Data:" << be32toh(i_tiDataArea->asciiData6) << ":";
287 ss << "0x4c ASCII Data:" << be32toh(i_tiDataArea->asciiData7) << ":";
288 ss << "0x50 Location:" << (int)i_tiDataArea->location << ":";
289 ss << "0x51 Code Sections:" << (int)i_tiDataArea->codeSection << ":";
290 ss << "0x52 Additional Size:" << (int)i_tiDataArea->additionalSize << ":";
291 ss << "0x53 Additional Data:" << (int)i_tiDataArea->andData;
292
293 std::string key, value;
294 char delim = ':';
295
296 while (std::getline(ss, key, delim))
297 {
298 std::getline(ss, value, delim);
299 i_map[key] = value;
300 }
301}
302
303/** @brief Parse the TI info data area into map as hostboot data */
304void parseHbTiInfo(std::map<std::string, std::string>& i_map,
305 TiDataArea* i_tiDataArea)
306{
Ben Tyner1c4b02e2020-11-09 14:00:29 -0600307 if (nullptr == i_tiDataArea)
308 {
309 return;
310 }
311
Ben Tyner40717722020-09-23 09:43:20 -0500312 std::stringstream ss;
313
314 ss << std::hex << std::showbase;
315 ss << "0x00 TI Area Valid:" << (int)i_tiDataArea->tiAreaValid << ":";
316 ss << "0x04 Reserved:" << (int)i_tiDataArea->reserved1 << ":";
317 ss << "0x05 HB_Term. Type:" << (int)i_tiDataArea->hbTerminateType << ":";
318 ss << "0x0c HB Dump Flag:" << (int)i_tiDataArea->hbDumpFlag << ":";
319 ss << "0x0d Source:" << (int)i_tiDataArea->source << ":";
320 ss << "0x10 HB Word 0:" << be32toh(i_tiDataArea->srcWord12HbWord0) << ":";
321 ss << "0x14 HB Word 2:" << be32toh(i_tiDataArea->srcWord13HbWord2) << ":";
322 ss << "0x18 HB Word 3:" << be32toh(i_tiDataArea->srcWord14HbWord3) << ":";
323 ss << "0x1c HB Word 4:" << be32toh(i_tiDataArea->srcWord15HbWord4) << ":";
324 ss << "0x20 HB Word 5:" << be32toh(i_tiDataArea->srcWord16HbWord5) << ":";
325 ss << "0x24 HB Word 6:" << be32toh(i_tiDataArea->srcWord17HbWord6) << ":";
326 ss << "0x28 HB Word 7:" << be32toh(i_tiDataArea->srcWord18HbWord7) << ":";
327 ss << "0x2c HB Word 8:" << be32toh(i_tiDataArea->srcWord19HbWord8) << ":";
328 ss << "0x30 error_data:" << be32toh(i_tiDataArea->asciiData0) << ":";
329 ss << "0x34 EID:" << be32toh(i_tiDataArea->asciiData1);
330
331 std::string key, value;
332 char delim = ':';
333
334 while (std::getline(ss, key, delim))
335 {
336 std::getline(ss, value, delim);
337 i_map[key] = value;
338 }
339}
340
341/** @brief Read state of autoreboot propertyi via dbus */
Ben Tynerff17f962020-09-23 08:21:19 -0500342bool autoRebootEnabled()
343{
344 // Use dbus get-property interface to read the autoreboot property
345 auto bus = sdbusplus::bus::new_system();
346 auto method =
347 bus.new_method_call("xyz.openbmc_project.Settings",
348 "/xyz/openbmc_project/control/host0/auto_reboot",
349 "org.freedesktop.DBus.Properties", "Get");
Ben Tyner40717722020-09-23 09:43:20 -0500350
Ben Tynerff17f962020-09-23 08:21:19 -0500351 method.append("xyz.openbmc_project.Control.Boot.RebootPolicy",
352 "AutoReboot");
Ben Tyner40717722020-09-23 09:43:20 -0500353
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500354 bool autoReboot = false; // assume autoreboot attribute not available
355
Ben Tynerff17f962020-09-23 08:21:19 -0500356 try
357 {
358 auto reply = bus.call(method);
Ben Tyner40717722020-09-23 09:43:20 -0500359
Ben Tynerff17f962020-09-23 08:21:19 -0500360 std::variant<bool> result;
361 reply.read(result);
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500362 autoReboot = std::get<bool>(result);
Ben Tynerff17f962020-09-23 08:21:19 -0500363 }
364 catch (const sdbusplus::exception::SdBusError& ec)
365 {
Ben Tynerff17f962020-09-23 08:21:19 -0500366 std::string traceMessage =
367 "Error in AutoReboot Get: " + std::string(ec.what());
368 trace<level::INFO>(traceMessage.c_str());
Ben Tynerff17f962020-09-23 08:21:19 -0500369 }
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500370
371 return autoReboot;
Ben Tynerff17f962020-09-23 08:21:19 -0500372}
Ben Tyner40717722020-09-23 09:43:20 -0500373
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600374} // namespace attn