blob: 56aae66689567e56a10c5c7e8ab95daf3423d246 [file] [log] [blame]
austinfcui444fa1c2022-02-08 10:20:37 -06001#include <fmt/format.h>
2
Ben Tynerbcf65a82020-12-01 08:46:36 -06003#include <attn/attn_common.hpp>
Ben Tyner5c5db652021-02-22 18:22:35 -06004#include <attn/attn_dbus.hpp>
Ben Tyner0f481a42021-10-19 11:23:43 -05005#include <attn/attn_dump.hpp>
Ben Tynerb797b3e2020-06-29 10:12:05 -05006#include <attn/attn_logging.hpp>
Ben Tynerf5210bb2021-01-05 12:58:10 -06007#include <attn/pel/pel_common.hpp>
Ben Tynerb797b3e2020-06-29 10:12:05 -05008#include <attn/ti_handler.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06009#include <sdbusplus/bus.hpp>
Ben Tynerff17f962020-09-23 08:21:19 -050010#include <sdbusplus/exception.hpp>
Ben Tyner93067162021-07-23 10:39:30 -050011#include <util/dbus.hpp>
austinfcuibfa831a2022-01-26 15:37:07 -060012#include <util/trace.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -060013
Ben Tyner40717722020-09-23 09:43:20 -050014#include <iomanip>
15#include <iostream>
16
Ben Tyner9ae5ca42020-02-28 13:13:50 -060017namespace attn
18{
19
Ben Tyner8c5e4f42020-10-28 11:11:55 -050020/**
21 * @brief Determine if this is a HB or PHYP TI event
22 *
23 * Use the TI info data area to determine if this is either a HB or a PHYP
24 * TI event then handle the event.
25 *
Ben Tynerf5210bb2021-01-05 12:58:10 -060026 * @param i_tiDataArea pointer to the TI info data
Ben Tyner8c5e4f42020-10-28 11:11:55 -050027 */
Ben Tyner792f32f2020-06-02 08:50:47 -050028int tiHandler(TiDataArea* i_tiDataArea)
Ben Tyner9ae5ca42020-02-28 13:13:50 -060029{
Ben Tynere4f5dbe2020-10-19 07:19:33 -050030 int rc = RC_SUCCESS;
Ben Tyner9ae5ca42020-02-28 13:13:50 -060031
Ben Tynerb8335562021-07-16 12:43:52 -050032 // capture some additional data for logs/traces
33 addHbStatusRegs();
34
Ben Tyner8c5e4f42020-10-28 11:11:55 -050035 // check TI data area if it is available
Ben Tynere4f5dbe2020-10-19 07:19:33 -050036 if (nullptr != i_tiDataArea)
Ben Tyner792f32f2020-06-02 08:50:47 -050037 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050038 // HB v. PHYP TI logic: Only hosboot will fill in hbTerminateType
Ben Tyner8882c322021-02-05 12:13:21 -060039 // and it will be non-zero. Only hostboot will fill out source and
40 // it it will be non-zero. Only PHYP will fill in srcFormat and it
41 // will be non-zero.
Ben Tyner8c5e4f42020-10-28 11:11:55 -050042 if ((0 == i_tiDataArea->hbTerminateType) &&
43 (0 == i_tiDataArea->source) && (0 != i_tiDataArea->srcFormat))
Ben Tynere4f5dbe2020-10-19 07:19:33 -050044 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050045 handlePhypTi(i_tiDataArea);
Ben Tynere4f5dbe2020-10-19 07:19:33 -050046 }
47 else
48 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050049 handleHbTi(i_tiDataArea);
Ben Tynere4f5dbe2020-10-19 07:19:33 -050050 }
Ben Tyner8c5e4f42020-10-28 11:11:55 -050051 }
52 else
53 {
Ben Tyner29651ef2021-02-08 10:51:03 -060054 // TI data was not available This should not happen since we provide
55 // a default TI info in the case where get TI info was not successful.
Ben Tyner7a0dd542021-02-12 09:33:44 -060056 eventAttentionFail((int)AttnSection::tiHandler | ATTN_INFO_NULL);
Ben Tyner29651ef2021-02-08 10:51:03 -060057 rc = RC_NOT_HANDLED;
Ben Tynere4f5dbe2020-10-19 07:19:33 -050058 }
Ben Tyner40717722020-09-23 09:43:20 -050059
Ben Tyner8c5e4f42020-10-28 11:11:55 -050060 return rc;
61}
Ben Tynere4f5dbe2020-10-19 07:19:33 -050062
Ben Tyner8c5e4f42020-10-28 11:11:55 -050063/**
Ben Tyner8c5e4f42020-10-28 11:11:55 -050064 * @brief Handle a PHYP terminate immediate special attention
65 *
66 * The TI info data area will contain information pertaining to the TI
67 * condition. We will wither quiesce the host or initiate a MPIPL depending
68 * depending on the auto reboot configuration. We will also create a PEL which
69 * will contain the TI info data and FFDC data captured in the system journal.
70 *
71 * @param i_tiDataArea pointer to TI information filled in by hostboot
72 */
73void handlePhypTi(TiDataArea* i_tiDataArea)
74{
austinfcuibfa831a2022-01-26 15:37:07 -060075 trace::inf("PHYP TI");
Ben Tyner8c5e4f42020-10-28 11:11:55 -050076
Ben Tyner8c5e4f42020-10-28 11:11:55 -050077 // gather additional data for PEL
78 std::map<std::string, std::string> tiAdditionalData;
Ben Tynere4f5dbe2020-10-19 07:19:33 -050079
Ben Tyner135793a2021-10-27 09:18:41 -050080 // make note of recoverable errors present
81 tiAdditionalData["recoverables"] = recoverableErrors() ? "true" : "false";
82
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
Ben Tyner9d4f91c2021-02-09 08:27:58 -060090 // Copy all ascii src chars to additional data
91 char srcChar[33]; // 32 ascii chars + null term
92 memcpy(srcChar, &(i_tiDataArea->asciiData0), 32);
Patrick Williams27dd6362023-05-10 07:51:20 -050093 srcChar[32] = 0;
Ben Tyner29651ef2021-02-08 10:51:03 -060094 tiAdditionalData["SrcAscii"] = std::string{srcChar};
95
96 // TI event
97 eventTerminate(tiAdditionalData, (char*)i_tiDataArea);
Ben Tyner8c5e4f42020-10-28 11:11:55 -050098 }
Ben Tyner29651ef2021-02-08 10:51:03 -060099 else
100 {
101 // TI data was not available This should not happen since we provide
102 // a default TI info in the case where get TI info was not successful.
Ben Tyner7a0dd542021-02-12 09:33:44 -0600103 eventAttentionFail((int)AttnSection::handlePhypTi | ATTN_INFO_NULL);
Ben Tyner29651ef2021-02-08 10:51:03 -0600104 }
Ben Tyner063f6bd2021-03-26 07:45:56 -0500105
106 // We are finished creating the event log entries so transition host to
107 // the required state.
Ben Tyner39fcf652021-10-19 20:38:29 -0500108 if (true == util::dbus::dumpPolicyEnabled())
Ben Tyner063f6bd2021-03-26 07:45:56 -0500109 {
Ben Tyner39fcf652021-10-19 20:38:29 -0500110 // MPIPL is considered a "dump" so we will qualify this transition with
111 // the dumpPolicyEnabled property. MPIPL is triggered by by starting
112 // the host "crash" target.
Ben Tyner93067162021-07-23 10:39:30 -0500113 util::dbus::transitionHost(util::dbus::HostState::Crash);
Ben Tyner063f6bd2021-03-26 07:45:56 -0500114 }
115 else
116 {
Ben Tyner39fcf652021-10-19 20:38:29 -0500117 // If dumpPolicyEnabled property is disabled we will quiesce the host
Ben Tyner93067162021-07-23 10:39:30 -0500118 util::dbus::transitionHost(util::dbus::HostState::Quiesce);
Ben Tyner063f6bd2021-03-26 07:45:56 -0500119 }
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500120}
121
122/**
Ben Tyner0f481a42021-10-19 11:23:43 -0500123 * @brief Handle a hostboot terminate immediate with SRC provided
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500124 *
Ben Tyner0f481a42021-10-19 11:23:43 -0500125 * The TI info will contain the log ID of the event log that has already been
126 * submitted by hostboot. In this case the attention handler does not need to
127 * create a PEL. A hostboot dump may be requested and the host will be
128 * transitioned.
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500129 *
130 * @param i_tiDataArea pointer to TI information filled in by hostboot
131 */
Ben Tyner0f481a42021-10-19 11:23:43 -0500132void handleHbTiWithEid(TiDataArea* i_tiDataArea)
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500133{
austinfcuibfa831a2022-01-26 15:37:07 -0600134 trace::inf("HB TI with PLID/EID");
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500135
Ben Tyner0f481a42021-10-19 11:23:43 -0500136 if (nullptr != i_tiDataArea)
137 {
138 // see if HB dump is requested
Ben Tynerac5bd052022-03-03 14:09:13 -0600139 if (i_tiDataArea->hbFlags & hbDumpFlag)
Ben Tyner0f481a42021-10-19 11:23:43 -0500140 {
141 // retrieve log ID from TI info data
142 uint32_t logId = be32toh(i_tiDataArea->asciiData1);
Zane Shelley611b3442021-11-19 16:02:01 -0600143 requestDump(logId, DumpParameters{0, DumpType::Hostboot});
Ben Tyner0f481a42021-10-19 11:23:43 -0500144 }
145 }
146
147 util::dbus::transitionHost(util::dbus::HostState::Quiesce);
148}
149
150/**
151 * @brief Handle a hostboot terminate immediate with SRC provided
152 *
153 * The TI info will contain the reason code and additional data necessary
154 * to create a PEL on behalf of hostboot. A hostboot dump may be created
155 * (after generating the PEL) and the host may be transitioned depending
156 * on the reason code.
157 *
158 * @param i_tiDataArea pointer to TI information filled in by hostboot
159 */
160void handleHbTiWithSrc(TiDataArea* i_tiDataArea)
161{
austinfcuibfa831a2022-01-26 15:37:07 -0600162 trace::inf("HB TI with SRC");
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500163
164 // handle specific hostboot reason codes
165 if (nullptr != i_tiDataArea)
166 {
Ben Tyner0f481a42021-10-19 11:23:43 -0500167 // Reason code is byte 2 and 3 of 4 byte srcWord12HbWord0
168 uint16_t reasonCode = be32toh(i_tiDataArea->srcWord12HbWord0);
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500169
austinfcuibfa831a2022-01-26 15:37:07 -0600170 trace::inf("reason code %04x", reasonCode);
Ben Tyner86aa97a2021-12-12 21:29:16 -0600171
172 // for clean shutdown (reason code 050B) no PEL and no dump
Ben Tyner0f481a42021-10-19 11:23:43 -0500173 if (reasonCode != HB_SRC_SHUTDOWN_REQUEST)
Ben Tyner29651ef2021-02-08 10:51:03 -0600174 {
Ben Tyner5c5db652021-02-22 18:22:35 -0600175 // gather additional data for PEL
176 std::map<std::string, std::string> tiAdditionalData;
177
Ben Tyner135793a2021-10-27 09:18:41 -0500178 // make note of recoverable errors present
Patrick Williams27dd6362023-05-10 07:51:20 -0500179 tiAdditionalData["recoverables"] = recoverableErrors() ? "true"
180 : "false";
Ben Tyner135793a2021-10-27 09:18:41 -0500181
Ben Tyner5c5db652021-02-22 18:22:35 -0600182 parseHbTiInfo(tiAdditionalData, i_tiDataArea);
183
Ben Tyner29651ef2021-02-08 10:51:03 -0600184 tiAdditionalData["Subsystem"] = std::to_string(
185 static_cast<uint8_t>(pel::SubsystemID::hostboot));
186
Ben Tyner5c5db652021-02-22 18:22:35 -0600187 // Translate hex src value to ascii. This results in an 8
188 // character SRC (hostboot SRC is 32 bits)
austinfcui444fa1c2022-02-08 10:20:37 -0600189 tiAdditionalData["SrcAscii"] =
190 fmt::format("{:08X}", be32toh(i_tiDataArea->srcWord12HbWord0));
Ben Tyner29651ef2021-02-08 10:51:03 -0600191
Ben Tyner86aa97a2021-12-12 21:29:16 -0600192 // dump flag is only valid for TI with EID (not TI with SRC)
austinfcuibfa831a2022-01-26 15:37:07 -0600193 trace::inf("Ignoring TI info dump flag for HB TI with SRC");
Ben Tyner86aa97a2021-12-12 21:29:16 -0600194 tiAdditionalData["Dump"] = "true";
Ben Tyner5c5db652021-02-22 18:22:35 -0600195
Ben Tynerac5bd052022-03-03 14:09:13 -0600196 // TI with SRC will honor hbNotVisibleFlag
197 if (i_tiDataArea->hbFlags & hbNotVisibleFlag)
198 {
199 tiAdditionalData["hidden"] = "true";
200 }
201
Ben Tyner5c5db652021-02-22 18:22:35 -0600202 // Generate event log
Ben Tyner29651ef2021-02-08 10:51:03 -0600203 eventTerminate(tiAdditionalData, (char*)i_tiDataArea);
204 }
Ben Tyner0f481a42021-10-19 11:23:43 -0500205
206 if (HB_SRC_KEY_TRANSITION != reasonCode)
Ben Tyner5c5db652021-02-22 18:22:35 -0600207 {
Ben Tyner0f481a42021-10-19 11:23:43 -0500208 util::dbus::transitionHost(util::dbus::HostState::Quiesce);
Ben Tyner5c5db652021-02-22 18:22:35 -0600209 }
Ben Tyner40717722020-09-23 09:43:20 -0500210 }
Ben Tyner0f481a42021-10-19 11:23:43 -0500211 else
Ben Tyner063f6bd2021-03-26 07:45:56 -0500212 {
Ben Tyner0f481a42021-10-19 11:23:43 -0500213 // TI data was not available, this should not happen
214 eventAttentionFail((int)AttnSection::handleHbTi | ATTN_INFO_NULL);
215 }
216}
217
218/**
219 * @brief Handle a hostboot terminate immediate special attention
220 *
221 * The TI info data area will contain information pertaining to the TI
222 * condition. The course of action to take regarding the host state will
223 * depend on the contents of the TI info data area. We will also create a
224 * PEL containing the TI info data and FFDC data captured in the system
225 * journal.
226 *
227 * @param i_tiDataArea pointer to TI information filled in by hostboot
228 */
229void handleHbTi(TiDataArea* i_tiDataArea)
230{
austinfcuibfa831a2022-01-26 15:37:07 -0600231 trace::inf("HB TI");
Ben Tyner0f481a42021-10-19 11:23:43 -0500232
233 // handle specific hostboot reason codes
234 if (nullptr != i_tiDataArea)
235 {
236 uint8_t terminateType = i_tiDataArea->hbTerminateType;
237
238 if (TI_WITH_SRC == terminateType)
239 {
240 handleHbTiWithSrc(i_tiDataArea);
241 }
242 else
243 {
244 handleHbTiWithEid(i_tiDataArea);
245 }
246 }
247 else
248 {
249 // TI data was not available, this should not happen
250 eventAttentionFail((int)AttnSection::handleHbTi | ATTN_INFO_NULL);
Ben Tyner063f6bd2021-03-26 07:45:56 -0500251 }
Ben Tyner40717722020-09-23 09:43:20 -0500252}
253
254/** @brief Parse the TI info data area into map as PHYP/OPAL data */
255void parsePhypOpalTiInfo(std::map<std::string, std::string>& i_map,
256 TiDataArea* i_tiDataArea)
257{
Ben Tyner1c4b02e2020-11-09 14:00:29 -0600258 if (nullptr == i_tiDataArea)
259 {
260 return;
261 }
262
Patrick Williams27dd6362023-05-10 07:51:20 -0500263 i_map["0x00 TI Area Valid"] = fmt::format("{:02x}",
264 i_tiDataArea->tiAreaValid);
austinfcui444fa1c2022-02-08 10:20:37 -0600265 i_map["0x01 Command"] = fmt::format("{:02x}", i_tiDataArea->command);
266 i_map["0x02 Num. Data Bytes"] =
267 fmt::format("{:04x}", be16toh(i_tiDataArea->numDataBytes));
268 i_map["0x04 Reserved"] = fmt::format("{:02x}", i_tiDataArea->reserved1);
269 i_map["0x06 HWDump Type"] =
270 fmt::format("{:04x}", be16toh(i_tiDataArea->hardwareDumpType));
271 i_map["0x08 SRC Format"] = fmt::format("{:02x}", i_tiDataArea->srcFormat);
Patrick Williams27dd6362023-05-10 07:51:20 -0500272 i_map["0x09 SRC Flags"] = fmt::format("{:02x}", i_tiDataArea->srcFlags);
273 i_map["0x0a Num. ASCII Words"] = fmt::format("{:02x}",
274 i_tiDataArea->numAsciiWords);
275 i_map["0x0b Num. Hex Words"] = fmt::format("{:02x}",
276 i_tiDataArea->numHexWords);
277 i_map["0x0e Length of SRC"] = fmt::format("{:04x}",
278 be16toh(i_tiDataArea->lenSrc));
austinfcui444fa1c2022-02-08 10:20:37 -0600279 i_map["0x10 SRC Word 12"] =
280 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord12HbWord0));
281 i_map["0x14 SRC Word 13"] =
282 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord13HbWord2));
283 i_map["0x18 SRC Word 14"] =
284 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord14HbWord3));
285 i_map["0x1c SRC Word 15"] =
286 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord15HbWord4));
287 i_map["0x20 SRC Word 16"] =
288 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord16HbWord5));
289 i_map["0x24 SRC Word 17"] =
290 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord17HbWord6));
291 i_map["0x28 SRC Word 18"] =
292 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord18HbWord7));
293 i_map["0x2c SRC Word 19"] =
294 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord19HbWord8));
Patrick Williams27dd6362023-05-10 07:51:20 -0500295 i_map["0x30 ASCII Data"] = fmt::format("{:08x}",
296 be32toh(i_tiDataArea->asciiData0));
297 i_map["0x34 ASCII Data"] = fmt::format("{:08x}",
298 be32toh(i_tiDataArea->asciiData1));
299 i_map["0x38 ASCII Data"] = fmt::format("{:08x}",
300 be32toh(i_tiDataArea->asciiData2));
301 i_map["0x3c ASCII Data"] = fmt::format("{:08x}",
302 be32toh(i_tiDataArea->asciiData3));
303 i_map["0x40 ASCII Data"] = fmt::format("{:08x}",
304 be32toh(i_tiDataArea->asciiData4));
305 i_map["0x44 ASCII Data"] = fmt::format("{:08x}",
306 be32toh(i_tiDataArea->asciiData5));
307 i_map["0x48 ASCII Data"] = fmt::format("{:08x}",
308 be32toh(i_tiDataArea->asciiData6));
309 i_map["0x4c ASCII Data"] = fmt::format("{:08x}",
310 be32toh(i_tiDataArea->asciiData7));
austinfcui444fa1c2022-02-08 10:20:37 -0600311 i_map["0x50 Location"] = fmt::format("{:02x}", i_tiDataArea->location);
Patrick Williams27dd6362023-05-10 07:51:20 -0500312 i_map["0x51 Code Sections"] = fmt::format("{:02x}",
313 i_tiDataArea->codeSection);
314 i_map["0x52 Additional Size"] = fmt::format("{:02x}",
315 i_tiDataArea->additionalSize);
316 i_map["0x53 Additional Data"] = fmt::format("{:02x}",
317 i_tiDataArea->andData);
Ben Tyner40717722020-09-23 09:43:20 -0500318}
319
320/** @brief Parse the TI info data area into map as hostboot data */
321void parseHbTiInfo(std::map<std::string, std::string>& i_map,
322 TiDataArea* i_tiDataArea)
323{
Ben Tyner1c4b02e2020-11-09 14:00:29 -0600324 if (nullptr == i_tiDataArea)
325 {
326 return;
327 }
328
Patrick Williams27dd6362023-05-10 07:51:20 -0500329 i_map["0x00 TI Area Valid"] = fmt::format("{:02x}",
330 i_tiDataArea->tiAreaValid);
austinfcui444fa1c2022-02-08 10:20:37 -0600331 i_map["0x04 Reserved"] = fmt::format("{:02x}", i_tiDataArea->reserved1);
Patrick Williams27dd6362023-05-10 07:51:20 -0500332 i_map["0x05 HB_Term. Type"] = fmt::format("{:02x}",
333 i_tiDataArea->hbTerminateType);
Ben Tynerac5bd052022-03-03 14:09:13 -0600334 i_map["0x0c HB Flags"] = fmt::format("{:02x}", i_tiDataArea->hbFlags);
Patrick Williams27dd6362023-05-10 07:51:20 -0500335 i_map["0x0d Source"] = fmt::format("{:02x}", i_tiDataArea->source);
austinfcui444fa1c2022-02-08 10:20:37 -0600336 i_map["0x10 HB Word 0"] =
337 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord12HbWord0));
338 i_map["0x14 HB Word 2"] =
339 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord13HbWord2));
340 i_map["0x18 HB Word 3"] =
341 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord14HbWord3));
342 i_map["0x1c HB Word 4"] =
343 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord15HbWord4));
344 i_map["0x20 HB Word 5"] =
345 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord16HbWord5));
346 i_map["0x24 HB Word 6"] =
347 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord17HbWord6));
348 i_map["0x28 HB Word 7"] =
349 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord18HbWord7));
350 i_map["0x2c HB Word 8"] =
351 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord19HbWord8));
Patrick Williams27dd6362023-05-10 07:51:20 -0500352 i_map["0x30 error_data"] = fmt::format("{:08x}",
353 be32toh(i_tiDataArea->asciiData0));
354 i_map["0x34 EID"] = fmt::format("{:08x}",
355 be32toh(i_tiDataArea->asciiData1));
Ben Tyner40717722020-09-23 09:43:20 -0500356}
357
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600358} // namespace attn