blob: bdd6f8a47d5c63732bb9ece7f249bae0b8997608 [file] [log] [blame]
Ben Tynerbcf65a82020-12-01 08:46:36 -06001#include <attn/attn_common.hpp>
Ben Tyner5c5db652021-02-22 18:22:35 -06002#include <attn/attn_dbus.hpp>
Ben Tyner0f481a42021-10-19 11:23:43 -05003#include <attn/attn_dump.hpp>
Ben Tynerb797b3e2020-06-29 10:12:05 -05004#include <attn/attn_logging.hpp>
Ben Tynerf5210bb2021-01-05 12:58:10 -06005#include <attn/pel/pel_common.hpp>
Ben Tynerb797b3e2020-06-29 10:12:05 -05006#include <attn/ti_handler.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06007#include <sdbusplus/bus.hpp>
Ben Tynerff17f962020-09-23 08:21:19 -05008#include <sdbusplus/exception.hpp>
Ben Tyner93067162021-07-23 10:39:30 -05009#include <util/dbus.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -060010
Ben Tyner40717722020-09-23 09:43:20 -050011#include <iomanip>
12#include <iostream>
13
Ben Tyner9ae5ca42020-02-28 13:13:50 -060014namespace attn
15{
16
Ben Tyner8c5e4f42020-10-28 11:11:55 -050017/**
18 * @brief Determine if this is a HB or PHYP TI event
19 *
20 * Use the TI info data area to determine if this is either a HB or a PHYP
21 * TI event then handle the event.
22 *
Ben Tynerf5210bb2021-01-05 12:58:10 -060023 * @param i_tiDataArea pointer to the TI info data
Ben Tyner8c5e4f42020-10-28 11:11:55 -050024 */
Ben Tyner792f32f2020-06-02 08:50:47 -050025int tiHandler(TiDataArea* i_tiDataArea)
Ben Tyner9ae5ca42020-02-28 13:13:50 -060026{
Ben Tynere4f5dbe2020-10-19 07:19:33 -050027 int rc = RC_SUCCESS;
Ben Tyner9ae5ca42020-02-28 13:13:50 -060028
Ben Tynerb8335562021-07-16 12:43:52 -050029 // capture some additional data for logs/traces
30 addHbStatusRegs();
31
Ben Tyner8c5e4f42020-10-28 11:11:55 -050032 // check TI data area if it is available
Ben Tynere4f5dbe2020-10-19 07:19:33 -050033 if (nullptr != i_tiDataArea)
Ben Tyner792f32f2020-06-02 08:50:47 -050034 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050035 // HB v. PHYP TI logic: Only hosboot will fill in hbTerminateType
Ben Tyner8882c322021-02-05 12:13:21 -060036 // and it will be non-zero. Only hostboot will fill out source and
37 // it it will be non-zero. Only PHYP will fill in srcFormat and it
38 // will be non-zero.
Ben Tyner8c5e4f42020-10-28 11:11:55 -050039 if ((0 == i_tiDataArea->hbTerminateType) &&
40 (0 == i_tiDataArea->source) && (0 != i_tiDataArea->srcFormat))
Ben Tynere4f5dbe2020-10-19 07:19:33 -050041 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050042 handlePhypTi(i_tiDataArea);
Ben Tynere4f5dbe2020-10-19 07:19:33 -050043 }
44 else
45 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050046 handleHbTi(i_tiDataArea);
Ben Tynere4f5dbe2020-10-19 07:19:33 -050047 }
Ben Tyner8c5e4f42020-10-28 11:11:55 -050048 }
49 else
50 {
Ben Tyner29651ef2021-02-08 10:51:03 -060051 // TI data was not available This should not happen since we provide
52 // a default TI info in the case where get TI info was not successful.
Ben Tyner7a0dd542021-02-12 09:33:44 -060053 eventAttentionFail((int)AttnSection::tiHandler | ATTN_INFO_NULL);
Ben Tyner29651ef2021-02-08 10:51:03 -060054 rc = RC_NOT_HANDLED;
Ben Tynere4f5dbe2020-10-19 07:19:33 -050055 }
Ben Tyner40717722020-09-23 09:43:20 -050056
Ben Tyner8c5e4f42020-10-28 11:11:55 -050057 return rc;
58}
Ben Tynere4f5dbe2020-10-19 07:19:33 -050059
Ben Tyner8c5e4f42020-10-28 11:11:55 -050060/**
Ben Tyner8c5e4f42020-10-28 11:11:55 -050061 * @brief Handle a PHYP terminate immediate special attention
62 *
63 * The TI info data area will contain information pertaining to the TI
64 * condition. We will wither quiesce the host or initiate a MPIPL depending
65 * depending on the auto reboot configuration. We will also create a PEL which
66 * will contain the TI info data and FFDC data captured in the system journal.
67 *
68 * @param i_tiDataArea pointer to TI information filled in by hostboot
69 */
70void handlePhypTi(TiDataArea* i_tiDataArea)
71{
72 trace<level::INFO>("PHYP TI");
73
Ben Tyner8c5e4f42020-10-28 11:11:55 -050074 // gather additional data for PEL
75 std::map<std::string, std::string> tiAdditionalData;
Ben Tynere4f5dbe2020-10-19 07:19:33 -050076
Ben Tyner135793a2021-10-27 09:18:41 -050077 // make note of recoverable errors present
78 tiAdditionalData["recoverables"] = recoverableErrors() ? "true" : "false";
79
Ben Tyner8c5e4f42020-10-28 11:11:55 -050080 if (nullptr != i_tiDataArea)
81 {
82 parsePhypOpalTiInfo(tiAdditionalData, i_tiDataArea);
Ben Tyner29651ef2021-02-08 10:51:03 -060083
84 tiAdditionalData["Subsystem"] =
85 std::to_string(static_cast<uint8_t>(pel::SubsystemID::hypervisor));
86
Ben Tyner9d4f91c2021-02-09 08:27:58 -060087 // Copy all ascii src chars to additional data
88 char srcChar[33]; // 32 ascii chars + null term
89 memcpy(srcChar, &(i_tiDataArea->asciiData0), 32);
90 srcChar[32] = 0;
Ben Tyner29651ef2021-02-08 10:51:03 -060091 tiAdditionalData["SrcAscii"] = std::string{srcChar};
92
93 // TI event
94 eventTerminate(tiAdditionalData, (char*)i_tiDataArea);
Ben Tyner8c5e4f42020-10-28 11:11:55 -050095 }
Ben Tyner29651ef2021-02-08 10:51:03 -060096 else
97 {
98 // TI data was not available This should not happen since we provide
99 // a default TI info in the case where get TI info was not successful.
Ben Tyner7a0dd542021-02-12 09:33:44 -0600100 eventAttentionFail((int)AttnSection::handlePhypTi | ATTN_INFO_NULL);
Ben Tyner29651ef2021-02-08 10:51:03 -0600101 }
Ben Tyner063f6bd2021-03-26 07:45:56 -0500102
103 // We are finished creating the event log entries so transition host to
104 // the required state.
Ben Tyner39fcf652021-10-19 20:38:29 -0500105 if (true == util::dbus::dumpPolicyEnabled())
Ben Tyner063f6bd2021-03-26 07:45:56 -0500106 {
Ben Tyner39fcf652021-10-19 20:38:29 -0500107 // MPIPL is considered a "dump" so we will qualify this transition with
108 // the dumpPolicyEnabled property. MPIPL is triggered by by starting
109 // the host "crash" target.
Ben Tyner93067162021-07-23 10:39:30 -0500110 util::dbus::transitionHost(util::dbus::HostState::Crash);
Ben Tyner063f6bd2021-03-26 07:45:56 -0500111 }
112 else
113 {
Ben Tyner39fcf652021-10-19 20:38:29 -0500114 // If dumpPolicyEnabled property is disabled we will quiesce the host
Ben Tyner93067162021-07-23 10:39:30 -0500115 util::dbus::transitionHost(util::dbus::HostState::Quiesce);
Ben Tyner063f6bd2021-03-26 07:45:56 -0500116 }
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500117}
118
119/**
Ben Tyner0f481a42021-10-19 11:23:43 -0500120 * @brief Handle a hostboot terminate immediate with SRC provided
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500121 *
Ben Tyner0f481a42021-10-19 11:23:43 -0500122 * The TI info will contain the log ID of the event log that has already been
123 * submitted by hostboot. In this case the attention handler does not need to
124 * create a PEL. A hostboot dump may be requested and the host will be
125 * transitioned.
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500126 *
127 * @param i_tiDataArea pointer to TI information filled in by hostboot
128 */
Ben Tyner0f481a42021-10-19 11:23:43 -0500129void handleHbTiWithEid(TiDataArea* i_tiDataArea)
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500130{
Ben Tyner0f481a42021-10-19 11:23:43 -0500131 trace<level::INFO>("HB TI with PLID/EID");
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500132
Ben Tyner0f481a42021-10-19 11:23:43 -0500133 if (nullptr != i_tiDataArea)
134 {
135 // see if HB dump is requested
136 if (0 != i_tiDataArea->hbDumpFlag)
137 {
138 // retrieve log ID from TI info data
139 uint32_t logId = be32toh(i_tiDataArea->asciiData1);
Zane Shelley611b3442021-11-19 16:02:01 -0600140 requestDump(logId, DumpParameters{0, DumpType::Hostboot});
Ben Tyner0f481a42021-10-19 11:23:43 -0500141 }
142 }
143
144 util::dbus::transitionHost(util::dbus::HostState::Quiesce);
145}
146
147/**
148 * @brief Handle a hostboot terminate immediate with SRC provided
149 *
150 * The TI info will contain the reason code and additional data necessary
151 * to create a PEL on behalf of hostboot. A hostboot dump may be created
152 * (after generating the PEL) and the host may be transitioned depending
153 * on the reason code.
154 *
155 * @param i_tiDataArea pointer to TI information filled in by hostboot
156 */
157void handleHbTiWithSrc(TiDataArea* i_tiDataArea)
158{
159 trace<level::INFO>("HB TI with SRC");
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500160
161 // handle specific hostboot reason codes
162 if (nullptr != i_tiDataArea)
163 {
Ben Tyner0f481a42021-10-19 11:23:43 -0500164 // Reason code is byte 2 and 3 of 4 byte srcWord12HbWord0
165 uint16_t reasonCode = be32toh(i_tiDataArea->srcWord12HbWord0);
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500166
Ben Tyner86aa97a2021-12-12 21:29:16 -0600167 // buffer for formatted string (+1 for null, just in case)
168 char buffer[sizeof("reason code 1234 ")];
169 sprintf(buffer, "reason code %04x", reasonCode);
170 trace<level::INFO>(buffer);
171
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
179 tiAdditionalData["recoverables"] =
180 recoverableErrors() ? "true" : "false";
181
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)
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600189 std::stringstream src;
Ben Tyner4bbcb382021-02-22 09:29:00 -0600190 src << std::setw(8) << std::setfill('0') << std::uppercase
191 << std::hex << be32toh(i_tiDataArea->srcWord12HbWord0);
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600192 tiAdditionalData["SrcAscii"] = src.str();
Ben Tyner29651ef2021-02-08 10:51:03 -0600193
Ben Tyner86aa97a2021-12-12 21:29:16 -0600194 // dump flag is only valid for TI with EID (not TI with SRC)
195 trace<level::INFO>("Ignoring TI info dump flag for HB TI with SRC");
196 tiAdditionalData["Dump"] = "true";
Ben Tyner5c5db652021-02-22 18:22:35 -0600197
198 // Generate event log
Ben Tyner29651ef2021-02-08 10:51:03 -0600199 eventTerminate(tiAdditionalData, (char*)i_tiDataArea);
200 }
Ben Tyner0f481a42021-10-19 11:23:43 -0500201
202 if (HB_SRC_KEY_TRANSITION != reasonCode)
Ben Tyner5c5db652021-02-22 18:22:35 -0600203 {
Ben Tyner0f481a42021-10-19 11:23:43 -0500204 util::dbus::transitionHost(util::dbus::HostState::Quiesce);
Ben Tyner5c5db652021-02-22 18:22:35 -0600205 }
Ben Tyner40717722020-09-23 09:43:20 -0500206 }
Ben Tyner0f481a42021-10-19 11:23:43 -0500207 else
Ben Tyner063f6bd2021-03-26 07:45:56 -0500208 {
Ben Tyner0f481a42021-10-19 11:23:43 -0500209 // TI data was not available, this should not happen
210 eventAttentionFail((int)AttnSection::handleHbTi | ATTN_INFO_NULL);
211 }
212}
213
214/**
215 * @brief Handle a hostboot terminate immediate special attention
216 *
217 * The TI info data area will contain information pertaining to the TI
218 * condition. The course of action to take regarding the host state will
219 * depend on the contents of the TI info data area. We will also create a
220 * PEL containing the TI info data and FFDC data captured in the system
221 * journal.
222 *
223 * @param i_tiDataArea pointer to TI information filled in by hostboot
224 */
225void handleHbTi(TiDataArea* i_tiDataArea)
226{
227 trace<level::INFO>("HB TI");
228
229 // handle specific hostboot reason codes
230 if (nullptr != i_tiDataArea)
231 {
232 uint8_t terminateType = i_tiDataArea->hbTerminateType;
233
234 if (TI_WITH_SRC == terminateType)
235 {
236 handleHbTiWithSrc(i_tiDataArea);
237 }
238 else
239 {
240 handleHbTiWithEid(i_tiDataArea);
241 }
242 }
243 else
244 {
245 // TI data was not available, this should not happen
246 eventAttentionFail((int)AttnSection::handleHbTi | ATTN_INFO_NULL);
Ben Tyner063f6bd2021-03-26 07:45:56 -0500247 }
Ben Tyner40717722020-09-23 09:43:20 -0500248}
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
Ben Tynerfeeea832021-04-06 10:08:11 -0500261 ss << "0x00 TI Area Valid:" << std::setw(2) << std::setfill('0') << std::hex
262 << (int)i_tiDataArea->tiAreaValid << ":";
263 ss << "0x01 Command:" << std::setw(2) << std::setfill('0') << std::hex
264 << (int)i_tiDataArea->command << ":";
265 ss << "0x02 Num. Data Bytes:" << std::setw(4) << std::setfill('0')
266 << std::hex << be16toh(i_tiDataArea->numDataBytes) << ":";
267 ss << "0x04 Reserved:" << std::setw(2) << std::setfill('0') << std::hex
268 << (int)i_tiDataArea->reserved1 << ":";
269 ss << "0x06 HWDump Type:" << std::setw(4) << std::setfill('0') << std::hex
270 << be16toh(i_tiDataArea->hardwareDumpType) << ":";
271 ss << "0x08 SRC Format:" << std::setw(2) << std::setfill('0') << std::hex
272 << (int)i_tiDataArea->srcFormat << ":";
273 ss << "0x09 SRC Flags:" << std::setw(2) << std::setfill('0') << std::hex
274 << (int)i_tiDataArea->srcFlags << ":";
275 ss << "0x0a Num. ASCII Words:" << std::setw(2) << std::setfill('0')
276 << std::hex << (int)i_tiDataArea->numAsciiWords << ":";
277 ss << "0x0b Num. Hex Words:" << std::setw(2) << std::setfill('0')
278 << std::hex << (int)i_tiDataArea->numHexWords << ":";
279 ss << "0x0e Length of SRC:" << std::setw(4) << std::setfill('0') << std::hex
280 << be16toh(i_tiDataArea->lenSrc) << ":";
281 ss << "0x10 SRC Word 12:" << std::setw(8) << std::setfill('0') << std::hex
282 << be32toh(i_tiDataArea->srcWord12HbWord0) << ":";
283 ss << "0x14 SRC Word 13:" << std::setw(8) << std::setfill('0') << std::hex
284 << be32toh(i_tiDataArea->srcWord13HbWord2) << ":";
285 ss << "0x18 SRC Word 14:" << std::setw(8) << std::setfill('0') << std::hex
286 << be32toh(i_tiDataArea->srcWord14HbWord3) << ":";
287 ss << "0x1c SRC Word 15:" << std::setw(8) << std::setfill('0') << std::hex
288 << be32toh(i_tiDataArea->srcWord15HbWord4) << ":";
289 ss << "0x20 SRC Word 16:" << std::setw(8) << std::setfill('0') << std::hex
290 << be32toh(i_tiDataArea->srcWord16HbWord5) << ":";
291 ss << "0x24 SRC Word 17:" << std::setw(8) << std::setfill('0') << std::hex
292 << be32toh(i_tiDataArea->srcWord17HbWord6) << ":";
293 ss << "0x28 SRC Word 18:" << std::setw(8) << std::setfill('0') << std::hex
294 << be32toh(i_tiDataArea->srcWord18HbWord7) << ":";
295 ss << "0x2c SRC Word 19:" << std::setw(8) << std::setfill('0') << std::hex
296 << be32toh(i_tiDataArea->srcWord19HbWord8) << ":";
297 ss << "0x30 ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
298 << be32toh(i_tiDataArea->asciiData0) << ":";
299 ss << "0x34 ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
300 << be32toh(i_tiDataArea->asciiData1) << ":";
301 ss << "0x38 ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
302 << be32toh(i_tiDataArea->asciiData2) << ":";
303 ss << "0x3c ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
304 << be32toh(i_tiDataArea->asciiData3) << ":";
305 ss << "0x40 ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
306 << be32toh(i_tiDataArea->asciiData4) << ":";
307 ss << "0x44 ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
308 << be32toh(i_tiDataArea->asciiData5) << ":";
309 ss << "0x48 ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
310 << be32toh(i_tiDataArea->asciiData6) << ":";
311 ss << "0x4c ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
312 << be32toh(i_tiDataArea->asciiData7) << ":";
313 ss << "0x50 Location:" << std::setw(2) << std::setfill('0') << std::hex
314 << (int)i_tiDataArea->location << ":";
315 ss << "0x51 Code Sections:" << std::setw(2) << std::setfill('0') << std::hex
316 << (int)i_tiDataArea->codeSection << ":";
317 ss << "0x52 Additional Size:" << std::setw(2) << std::setfill('0')
318 << std::hex << (int)i_tiDataArea->additionalSize << ":";
319 ss << "0x53 Additional Data:" << std::setw(2) << std::setfill('0')
320 << std::hex << (int)i_tiDataArea->andData;
Ben Tyner40717722020-09-23 09:43:20 -0500321
322 std::string key, value;
323 char delim = ':';
324
325 while (std::getline(ss, key, delim))
326 {
327 std::getline(ss, value, delim);
328 i_map[key] = value;
329 }
330}
331
332/** @brief Parse the TI info data area into map as hostboot data */
333void parseHbTiInfo(std::map<std::string, std::string>& i_map,
334 TiDataArea* i_tiDataArea)
335{
Ben Tyner1c4b02e2020-11-09 14:00:29 -0600336 if (nullptr == i_tiDataArea)
337 {
338 return;
339 }
340
Ben Tyner40717722020-09-23 09:43:20 -0500341 std::stringstream ss;
342
Ben Tynerfeeea832021-04-06 10:08:11 -0500343 ss << "0x00 TI Area Valid:" << std::setw(2) << std::setfill('0') << std::hex
344 << (int)i_tiDataArea->tiAreaValid << ":";
345 ss << "0x04 Reserved:" << std::setw(2) << std::setfill('0') << std::hex
346 << (int)i_tiDataArea->reserved1 << ":";
347 ss << "0x05 HB_Term. Type:" << std::setw(2) << std::setfill('0') << std::hex
348 << (int)i_tiDataArea->hbTerminateType << ":";
349 ss << "0x0c HB Dump Flag:" << std::setw(2) << std::setfill('0') << std::hex
350 << (int)i_tiDataArea->hbDumpFlag << ":";
351 ss << "0x0d Source:" << std::setw(2) << std::setfill('0') << std::hex
352 << (int)i_tiDataArea->source << ":";
353 ss << "0x10 HB Word 0:" << std::setw(8) << std::setfill('0') << std::hex
354 << be32toh(i_tiDataArea->srcWord12HbWord0) << ":";
355 ss << "0x14 HB Word 2:" << std::setw(8) << std::setfill('0') << std::hex
356 << be32toh(i_tiDataArea->srcWord13HbWord2) << ":";
357 ss << "0x18 HB Word 3:" << std::setw(8) << std::setfill('0') << std::hex
358 << be32toh(i_tiDataArea->srcWord14HbWord3) << ":";
359 ss << "0x1c HB Word 4:" << std::setw(8) << std::setfill('0') << std::hex
360 << be32toh(i_tiDataArea->srcWord15HbWord4) << ":";
361 ss << "0x20 HB Word 5:" << std::setw(8) << std::setfill('0') << std::hex
362 << be32toh(i_tiDataArea->srcWord16HbWord5) << ":";
363 ss << "0x24 HB Word 6:" << std::setw(8) << std::setfill('0') << std::hex
364 << be32toh(i_tiDataArea->srcWord17HbWord6) << ":";
365 ss << "0x28 HB Word 7:" << std::setw(8) << std::setfill('0') << std::hex
366 << be32toh(i_tiDataArea->srcWord18HbWord7) << ":";
367 ss << "0x2c HB Word 8:" << std::setw(8) << std::setfill('0') << std::hex
368 << be32toh(i_tiDataArea->srcWord19HbWord8) << ":";
369 ss << "0x30 error_data:" << std::setw(8) << std::setfill('0') << std::hex
370 << be32toh(i_tiDataArea->asciiData0) << ":";
371 ss << "0x34 EID:" << std::setw(8) << std::setfill('0') << std::hex
372 << be32toh(i_tiDataArea->asciiData1);
Ben Tyner40717722020-09-23 09:43:20 -0500373
374 std::string key, value;
375 char delim = ':';
376
377 while (std::getline(ss, key, delim))
378 {
379 std::getline(ss, value, delim);
380 i_map[key] = value;
381 }
382}
383
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600384} // namespace attn