blob: f04f1118cd6d2f466b3bad0906e88322f63120ec [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 {
Ben Tyner29651ef2021-02-08 10:51:03 -060046 // TI data was not available This should not happen since we provide
47 // a default TI info in the case where get TI info was not successful.
48 eventAttentionFail(ATTN_INFO_NULL);
49 rc = RC_NOT_HANDLED;
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 Tyner29651ef2021-02-08 10:51:03 -060086
87 tiAdditionalData["Subsystem"] =
88 std::to_string(static_cast<uint8_t>(pel::SubsystemID::hypervisor));
89
90 // copy ascii src chars to additional data
91 char srcChar[9]; // 8 char src + null term
92 memcpy(srcChar, &(i_tiDataArea->asciiData0), 4);
93 memcpy(&srcChar[4], &(i_tiDataArea->asciiData1), 4);
94 srcChar[8] = 0;
95 tiAdditionalData["SrcAscii"] = std::string{srcChar};
96
97 // TI event
98 eventTerminate(tiAdditionalData, (char*)i_tiDataArea);
Ben Tyner8c5e4f42020-10-28 11:11:55 -050099 }
Ben Tyner29651ef2021-02-08 10:51:03 -0600100 else
101 {
102 // TI data was not available This should not happen since we provide
103 // a default TI info in the case where get TI info was not successful.
104 eventAttentionFail(ATTN_INFO_NULL);
105 }
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500106}
107
108/**
109 * @brief Handle a hostboot terminate immediate special attention
110 *
111 * The TI info data area will contain information pertaining to the TI
112 * condition. The course of action to take regarding the host state will
113 * depend on the contents of the TI info data area. We will also create a
114 * PEL containing the TI info data and FFDC data captured in the system
115 * journal.
116 *
117 * @param i_tiDataArea pointer to TI information filled in by hostboot
118 */
119void handleHbTi(TiDataArea* i_tiDataArea)
120{
121 trace<level::INFO>("HB TI");
122
123 bool hbDumpRequested = true; // HB dump is common case
124 bool generatePel = true; // assume PEL will be created
125 bool terminateHost = true; // transition host state
126
127 // handle specific hostboot reason codes
128 if (nullptr != i_tiDataArea)
129 {
Ben Tyner8882c322021-02-05 12:13:21 -0600130 std::stringstream ss; // stream object for tracing
131 std::string strobj; // string object for tracing
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500132
133 switch (i_tiDataArea->hbTerminateType)
134 {
135 case TI_WITH_PLID:
136 case TI_WITH_EID:
Ben Tyner8882c322021-02-05 12:13:21 -0600137
138 // trace this value
139 ss.str(std::string()); // empty the stream
140 ss.clear(); // clear the stream
141 ss << "TI with PLID/EID: " << std::hex << std::showbase
142 << std::setw(8) << std::setfill('0')
143 << be32toh(i_tiDataArea->asciiData1);
144 strobj = ss.str();
145 trace<level::INFO>(strobj.c_str());
146
147 // see if HB dump is requested
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500148 if (0 == i_tiDataArea->hbDumpFlag)
149 {
150 hbDumpRequested = false; // no HB dump requested
151 }
152 break;
153 case TI_WITH_SRC:
Ben Tyner8882c322021-02-05 12:13:21 -0600154 // Reason code is byte 2 and 3 of 4 byte srcWord12HbWord0
155 uint16_t reasonCode = be32toh(i_tiDataArea->srcWord12HbWord0);
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500156
Ben Tyner8882c322021-02-05 12:13:21 -0600157 // trace this value
158 ss.str(std::string()); // empty the stream
159 ss.clear(); // clear the stream
160 ss << "TI with SRC: " << std::hex << std::showbase
161 << std::setw(4) << std::setfill('0') << (int)reasonCode;
162 strobj = ss.str();
163 trace<level::INFO>(strobj.c_str());
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500164
Ben Tyner8882c322021-02-05 12:13:21 -0600165 switch (reasonCode)
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500166 {
167 case HB_SRC_SHUTDOWN_REQUEST:
168 trace<level::INFO>("shutdown request");
Ben Tyner8882c322021-02-05 12:13:21 -0600169 generatePel = false;
170 hbDumpRequested = false;
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500171 break;
172 case HB_SRC_KEY_TRANSITION:
Ben Tyner8882c322021-02-05 12:13:21 -0600173 // Note: Should never see this so lets leave
174 // hbDumpRequested == true so we can figure out why
175 // we are here.
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500176 trace<level::INFO>("key transition");
177 terminateHost = false;
178 break;
179 case HB_SRC_INSUFFICIENT_HW:
180 trace<level::INFO>("insufficient hardware");
181 break;
182 case HB_SRC_TPM_FAIL:
183 trace<level::INFO>("TPM fail");
184 break;
185 case HB_SRC_ROM_VERIFY:
186 trace<level::INFO>("ROM verify");
187 break;
188 case HB_SRC_EXT_MISMATCH:
189 trace<level::INFO>("EXT mismatch");
190 break;
191 case HB_SRC_ECC_UE:
192 trace<level::INFO>("ECC UE");
193 break;
194 case HB_SRC_UNSUPPORTED_MODE:
195 trace<level::INFO>("unsupported mode");
196 break;
197 case HB_SRC_UNSUPPORTED_SFCRANGE:
198 trace<level::INFO>("unsupported SFC range");
199 break;
200 case HB_SRC_PARTITION_TABLE:
201 trace<level::INFO>("partition table invalid");
202 break;
203 case HB_SRC_UNSUPPORTED_HARDWARE:
204 trace<level::INFO>("unsupported hardware");
205 break;
206 case HB_SRC_PNOR_CORRUPTION:
207 trace<level::INFO>("PNOR corruption");
208 break;
209 default:
210 trace<level::INFO>("reason: other");
211 }
212
213 break;
214 }
215 }
216
217 if (true == terminateHost)
218 {
219 // if hostboot dump is requested initiate dump
220 if (hbDumpRequested)
221 {
222 // Until HB dump support available just quiesce the host - once
223 // dump support is available the dump component will transition
224 // (ipl/halt) the host.
Ben Tynerbcf65a82020-12-01 08:46:36 -0600225 transitionHost(HostState::Quiesce);
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500226 }
227 else
228 {
229 // Quiese the host - when the host is quiesced it will either
230 // "halt" or IPL depending on autoreboot setting.
Ben Tynerbcf65a82020-12-01 08:46:36 -0600231 transitionHost(HostState::Quiesce);
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500232 }
233 }
234
235 // gather additional data for PEL
236 std::map<std::string, std::string> tiAdditionalData;
237
238 if (nullptr != i_tiDataArea)
239 {
240 parseHbTiInfo(tiAdditionalData, i_tiDataArea);
Ben Tyner29651ef2021-02-08 10:51:03 -0600241
242 if (true == generatePel)
243 {
244 tiAdditionalData["Subsystem"] = std::to_string(
245 static_cast<uint8_t>(pel::SubsystemID::hostboot));
246
247 char srcChar[8];
248 memcpy(srcChar, &(i_tiDataArea->srcWord12HbWord0), 4);
249 memcpy(&srcChar[4], &(i_tiDataArea->asciiData1), 4);
250 tiAdditionalData["SrcAscii"] = std::string{srcChar};
251
252 eventTerminate(tiAdditionalData, (char*)i_tiDataArea);
253 }
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500254 }
Ben Tyner29651ef2021-02-08 10:51:03 -0600255 else
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500256 {
Ben Tyner29651ef2021-02-08 10:51:03 -0600257 // TI data was not available This should not happen since we provide
258 // a default TI info in the case where get TI info was not successful.
259 eventAttentionFail(ATTN_INFO_NULL);
Ben Tyner40717722020-09-23 09:43:20 -0500260 }
261}
262
263/** @brief Parse the TI info data area into map as PHYP/OPAL data */
264void parsePhypOpalTiInfo(std::map<std::string, std::string>& i_map,
265 TiDataArea* i_tiDataArea)
266{
Ben Tyner1c4b02e2020-11-09 14:00:29 -0600267 if (nullptr == i_tiDataArea)
268 {
269 return;
270 }
271
Ben Tyner40717722020-09-23 09:43:20 -0500272 std::stringstream ss;
273
274 ss << std::hex << std::showbase;
275 ss << "0x00 TI Area Valid:" << (int)i_tiDataArea->tiAreaValid << ":";
276 ss << "0x01 Command:" << (int)i_tiDataArea->command << ":";
277 ss << "0x02 Num. Data Bytes:" << be16toh(i_tiDataArea->numDataBytes) << ":";
278 ss << "0x04 Reserved:" << (int)i_tiDataArea->reserved1 << ":";
279 ss << "0x06 HWDump Type:" << be16toh(i_tiDataArea->hardwareDumpType) << ":";
280 ss << "0x08 SRC Format:" << (int)i_tiDataArea->srcFormat << ":";
281 ss << "0x09 SRC Flags:" << (int)i_tiDataArea->srcFlags << ":";
282 ss << "0x0a Num. ASCII Words:" << (int)i_tiDataArea->numAsciiWords << ":";
283 ss << "0x0b Num. Hex Words:" << (int)i_tiDataArea->numHexWords << ":";
284 ss << "0x0e Length of SRC:" << be16toh(i_tiDataArea->lenSrc) << ":";
285 ss << "0x10 SRC Word 12:" << be32toh(i_tiDataArea->srcWord12HbWord0) << ":";
286 ss << "0x14 SRC Word 13:" << be32toh(i_tiDataArea->srcWord13HbWord2) << ":";
287 ss << "0x18 SRC Word 14:" << be32toh(i_tiDataArea->srcWord14HbWord3) << ":";
288 ss << "0x1c SRC Word 15:" << be32toh(i_tiDataArea->srcWord15HbWord4) << ":";
289 ss << "0x20 SRC Word 16:" << be32toh(i_tiDataArea->srcWord16HbWord5) << ":";
290 ss << "0x24 SRC Word 17:" << be32toh(i_tiDataArea->srcWord17HbWord6) << ":";
291 ss << "0x28 SRC Word 18:" << be32toh(i_tiDataArea->srcWord18HbWord7) << ":";
292 ss << "0x2c SRC Word 19:" << be32toh(i_tiDataArea->srcWord19HbWord8) << ":";
293 ss << "0x30 ASCII Data:" << be32toh(i_tiDataArea->asciiData0) << ":";
294 ss << "0x34 ASCII Data:" << be32toh(i_tiDataArea->asciiData1) << ":";
295 ss << "0x38 ASCII Data:" << be32toh(i_tiDataArea->asciiData2) << ":";
296 ss << "0x3c ASCII Data:" << be32toh(i_tiDataArea->asciiData3) << ":";
297 ss << "0x40 ASCII Data:" << be32toh(i_tiDataArea->asciiData4) << ":";
298 ss << "0x44 ASCII Data:" << be32toh(i_tiDataArea->asciiData5) << ":";
299 ss << "0x48 ASCII Data:" << be32toh(i_tiDataArea->asciiData6) << ":";
300 ss << "0x4c ASCII Data:" << be32toh(i_tiDataArea->asciiData7) << ":";
301 ss << "0x50 Location:" << (int)i_tiDataArea->location << ":";
302 ss << "0x51 Code Sections:" << (int)i_tiDataArea->codeSection << ":";
303 ss << "0x52 Additional Size:" << (int)i_tiDataArea->additionalSize << ":";
304 ss << "0x53 Additional Data:" << (int)i_tiDataArea->andData;
305
306 std::string key, value;
307 char delim = ':';
308
309 while (std::getline(ss, key, delim))
310 {
311 std::getline(ss, value, delim);
312 i_map[key] = value;
313 }
314}
315
316/** @brief Parse the TI info data area into map as hostboot data */
317void parseHbTiInfo(std::map<std::string, std::string>& i_map,
318 TiDataArea* i_tiDataArea)
319{
Ben Tyner1c4b02e2020-11-09 14:00:29 -0600320 if (nullptr == i_tiDataArea)
321 {
322 return;
323 }
324
Ben Tyner40717722020-09-23 09:43:20 -0500325 std::stringstream ss;
326
327 ss << std::hex << std::showbase;
328 ss << "0x00 TI Area Valid:" << (int)i_tiDataArea->tiAreaValid << ":";
329 ss << "0x04 Reserved:" << (int)i_tiDataArea->reserved1 << ":";
330 ss << "0x05 HB_Term. Type:" << (int)i_tiDataArea->hbTerminateType << ":";
331 ss << "0x0c HB Dump Flag:" << (int)i_tiDataArea->hbDumpFlag << ":";
332 ss << "0x0d Source:" << (int)i_tiDataArea->source << ":";
333 ss << "0x10 HB Word 0:" << be32toh(i_tiDataArea->srcWord12HbWord0) << ":";
334 ss << "0x14 HB Word 2:" << be32toh(i_tiDataArea->srcWord13HbWord2) << ":";
335 ss << "0x18 HB Word 3:" << be32toh(i_tiDataArea->srcWord14HbWord3) << ":";
336 ss << "0x1c HB Word 4:" << be32toh(i_tiDataArea->srcWord15HbWord4) << ":";
337 ss << "0x20 HB Word 5:" << be32toh(i_tiDataArea->srcWord16HbWord5) << ":";
338 ss << "0x24 HB Word 6:" << be32toh(i_tiDataArea->srcWord17HbWord6) << ":";
339 ss << "0x28 HB Word 7:" << be32toh(i_tiDataArea->srcWord18HbWord7) << ":";
340 ss << "0x2c HB Word 8:" << be32toh(i_tiDataArea->srcWord19HbWord8) << ":";
341 ss << "0x30 error_data:" << be32toh(i_tiDataArea->asciiData0) << ":";
342 ss << "0x34 EID:" << be32toh(i_tiDataArea->asciiData1);
343
344 std::string key, value;
345 char delim = ':';
346
347 while (std::getline(ss, key, delim))
348 {
349 std::getline(ss, value, delim);
350 i_map[key] = value;
351 }
352}
353
354/** @brief Read state of autoreboot propertyi via dbus */
Ben Tynerff17f962020-09-23 08:21:19 -0500355bool autoRebootEnabled()
356{
357 // Use dbus get-property interface to read the autoreboot property
358 auto bus = sdbusplus::bus::new_system();
359 auto method =
360 bus.new_method_call("xyz.openbmc_project.Settings",
361 "/xyz/openbmc_project/control/host0/auto_reboot",
362 "org.freedesktop.DBus.Properties", "Get");
Ben Tyner40717722020-09-23 09:43:20 -0500363
Ben Tynerff17f962020-09-23 08:21:19 -0500364 method.append("xyz.openbmc_project.Control.Boot.RebootPolicy",
365 "AutoReboot");
Ben Tyner40717722020-09-23 09:43:20 -0500366
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500367 bool autoReboot = false; // assume autoreboot attribute not available
368
Ben Tynerff17f962020-09-23 08:21:19 -0500369 try
370 {
371 auto reply = bus.call(method);
Ben Tyner40717722020-09-23 09:43:20 -0500372
Ben Tynerff17f962020-09-23 08:21:19 -0500373 std::variant<bool> result;
374 reply.read(result);
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500375 autoReboot = std::get<bool>(result);
Ben Tynerff17f962020-09-23 08:21:19 -0500376 }
377 catch (const sdbusplus::exception::SdBusError& ec)
378 {
Ben Tynerff17f962020-09-23 08:21:19 -0500379 std::string traceMessage =
380 "Error in AutoReboot Get: " + std::string(ec.what());
381 trace<level::INFO>(traceMessage.c_str());
Ben Tynerff17f962020-09-23 08:21:19 -0500382 }
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500383
384 return autoReboot;
Ben Tynerff17f962020-09-23 08:21:19 -0500385}
Ben Tyner40717722020-09-23 09:43:20 -0500386
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600387} // namespace attn