blob: 0ae0db8c1b2cbfda660d975d681d7b4eb853ef80 [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);
93 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
139 if (0 != i_tiDataArea->hbDumpFlag)
140 {
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
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)
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
196 // Generate event log
Ben Tyner29651ef2021-02-08 10:51:03 -0600197 eventTerminate(tiAdditionalData, (char*)i_tiDataArea);
198 }
Ben Tyner0f481a42021-10-19 11:23:43 -0500199
200 if (HB_SRC_KEY_TRANSITION != reasonCode)
Ben Tyner5c5db652021-02-22 18:22:35 -0600201 {
Ben Tyner0f481a42021-10-19 11:23:43 -0500202 util::dbus::transitionHost(util::dbus::HostState::Quiesce);
Ben Tyner5c5db652021-02-22 18:22:35 -0600203 }
Ben Tyner40717722020-09-23 09:43:20 -0500204 }
Ben Tyner0f481a42021-10-19 11:23:43 -0500205 else
Ben Tyner063f6bd2021-03-26 07:45:56 -0500206 {
Ben Tyner0f481a42021-10-19 11:23:43 -0500207 // TI data was not available, this should not happen
208 eventAttentionFail((int)AttnSection::handleHbTi | ATTN_INFO_NULL);
209 }
210}
211
212/**
213 * @brief Handle a hostboot terminate immediate special attention
214 *
215 * The TI info data area will contain information pertaining to the TI
216 * condition. The course of action to take regarding the host state will
217 * depend on the contents of the TI info data area. We will also create a
218 * PEL containing the TI info data and FFDC data captured in the system
219 * journal.
220 *
221 * @param i_tiDataArea pointer to TI information filled in by hostboot
222 */
223void handleHbTi(TiDataArea* i_tiDataArea)
224{
austinfcuibfa831a2022-01-26 15:37:07 -0600225 trace::inf("HB TI");
Ben Tyner0f481a42021-10-19 11:23:43 -0500226
227 // handle specific hostboot reason codes
228 if (nullptr != i_tiDataArea)
229 {
230 uint8_t terminateType = i_tiDataArea->hbTerminateType;
231
232 if (TI_WITH_SRC == terminateType)
233 {
234 handleHbTiWithSrc(i_tiDataArea);
235 }
236 else
237 {
238 handleHbTiWithEid(i_tiDataArea);
239 }
240 }
241 else
242 {
243 // TI data was not available, this should not happen
244 eventAttentionFail((int)AttnSection::handleHbTi | ATTN_INFO_NULL);
Ben Tyner063f6bd2021-03-26 07:45:56 -0500245 }
Ben Tyner40717722020-09-23 09:43:20 -0500246}
247
248/** @brief Parse the TI info data area into map as PHYP/OPAL data */
249void parsePhypOpalTiInfo(std::map<std::string, std::string>& i_map,
250 TiDataArea* i_tiDataArea)
251{
Ben Tyner1c4b02e2020-11-09 14:00:29 -0600252 if (nullptr == i_tiDataArea)
253 {
254 return;
255 }
256
austinfcui444fa1c2022-02-08 10:20:37 -0600257 i_map["0x00 TI Area Valid"] =
258 fmt::format("{:02x}", i_tiDataArea->tiAreaValid);
259 i_map["0x01 Command"] = fmt::format("{:02x}", i_tiDataArea->command);
260 i_map["0x02 Num. Data Bytes"] =
261 fmt::format("{:04x}", be16toh(i_tiDataArea->numDataBytes));
262 i_map["0x04 Reserved"] = fmt::format("{:02x}", i_tiDataArea->reserved1);
263 i_map["0x06 HWDump Type"] =
264 fmt::format("{:04x}", be16toh(i_tiDataArea->hardwareDumpType));
265 i_map["0x08 SRC Format"] = fmt::format("{:02x}", i_tiDataArea->srcFormat);
266 i_map["0x09 SRC Flags"] = fmt::format("{:02x}", i_tiDataArea->srcFlags);
267 i_map["0x0a Num. ASCII Words"] =
268 fmt::format("{:02x}", i_tiDataArea->numAsciiWords);
269 i_map["0x0b Num. Hex Words"] =
270 fmt::format("{:02x}", i_tiDataArea->numHexWords);
271 i_map["0x0e Length of SRC"] =
272 fmt::format("{:04x}", be16toh(i_tiDataArea->lenSrc));
273 i_map["0x10 SRC Word 12"] =
274 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord12HbWord0));
275 i_map["0x14 SRC Word 13"] =
276 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord13HbWord2));
277 i_map["0x18 SRC Word 14"] =
278 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord14HbWord3));
279 i_map["0x1c SRC Word 15"] =
280 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord15HbWord4));
281 i_map["0x20 SRC Word 16"] =
282 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord16HbWord5));
283 i_map["0x24 SRC Word 17"] =
284 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord17HbWord6));
285 i_map["0x28 SRC Word 18"] =
286 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord18HbWord7));
287 i_map["0x2c SRC Word 19"] =
288 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord19HbWord8));
289 i_map["0x30 ASCII Data"] =
290 fmt::format("{:08x}", be32toh(i_tiDataArea->asciiData0));
291 i_map["0x34 ASCII Data"] =
292 fmt::format("{:08x}", be32toh(i_tiDataArea->asciiData1));
293 i_map["0x38 ASCII Data"] =
294 fmt::format("{:08x}", be32toh(i_tiDataArea->asciiData2));
295 i_map["0x3c ASCII Data"] =
296 fmt::format("{:08x}", be32toh(i_tiDataArea->asciiData3));
297 i_map["0x40 ASCII Data"] =
298 fmt::format("{:08x}", be32toh(i_tiDataArea->asciiData4));
299 i_map["0x44 ASCII Data"] =
300 fmt::format("{:08x}", be32toh(i_tiDataArea->asciiData5));
301 i_map["0x48 ASCII Data"] =
302 fmt::format("{:08x}", be32toh(i_tiDataArea->asciiData6));
303 i_map["0x4c ASCII Data"] =
304 fmt::format("{:08x}", be32toh(i_tiDataArea->asciiData7));
305 i_map["0x50 Location"] = fmt::format("{:02x}", i_tiDataArea->location);
306 i_map["0x51 Code Sections"] =
307 fmt::format("{:02x}", i_tiDataArea->codeSection);
308 i_map["0x52 Additional Size"] =
309 fmt::format("{:02x}", i_tiDataArea->additionalSize);
310 i_map["0x53 Additional Data"] =
311 fmt::format("{:02x}", i_tiDataArea->andData);
Ben Tyner40717722020-09-23 09:43:20 -0500312}
313
314/** @brief Parse the TI info data area into map as hostboot data */
315void parseHbTiInfo(std::map<std::string, std::string>& i_map,
316 TiDataArea* i_tiDataArea)
317{
Ben Tyner1c4b02e2020-11-09 14:00:29 -0600318 if (nullptr == i_tiDataArea)
319 {
320 return;
321 }
322
austinfcui444fa1c2022-02-08 10:20:37 -0600323 i_map["0x00 TI Area Valid"] =
324 fmt::format("{:02x}", i_tiDataArea->tiAreaValid);
325 i_map["0x04 Reserved"] = fmt::format("{:02x}", i_tiDataArea->reserved1);
326 i_map["0x05 HB_Term. Type"] =
327 fmt::format("{:02x}", i_tiDataArea->hbTerminateType);
328 i_map["0x0c HB Dump Flag"] =
329 fmt::format("{:02x}", i_tiDataArea->hbDumpFlag);
330 i_map["0x0d Source"] = fmt::format("{:02x}", i_tiDataArea->source);
331 i_map["0x10 HB Word 0"] =
332 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord12HbWord0));
333 i_map["0x14 HB Word 2"] =
334 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord13HbWord2));
335 i_map["0x18 HB Word 3"] =
336 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord14HbWord3));
337 i_map["0x1c HB Word 4"] =
338 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord15HbWord4));
339 i_map["0x20 HB Word 5"] =
340 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord16HbWord5));
341 i_map["0x24 HB Word 6"] =
342 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord17HbWord6));
343 i_map["0x28 HB Word 7"] =
344 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord18HbWord7));
345 i_map["0x2c HB Word 8"] =
346 fmt::format("{:08x}", be32toh(i_tiDataArea->srcWord19HbWord8));
347 i_map["0x30 error_data"] =
348 fmt::format("{:08x}", be32toh(i_tiDataArea->asciiData0));
349 i_map["0x34 EID"] =
350 fmt::format("{:08x}", be32toh(i_tiDataArea->asciiData1));
Ben Tyner40717722020-09-23 09:43:20 -0500351}
352
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600353} // namespace attn