blob: 8ecb64bab9ce5c605f6ad034b8616a69e7eff0a2 [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 Tynerb797b3e2020-06-29 10:12:05 -05003#include <attn/attn_handler.hpp>
4#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 Tyner9ae5ca42020-02-28 13:13:50 -06009
Ben Tyner40717722020-09-23 09:43:20 -050010#include <iomanip>
11#include <iostream>
12
Ben Tyner9ae5ca42020-02-28 13:13:50 -060013namespace attn
14{
15
Ben Tyner8c5e4f42020-10-28 11:11:55 -050016/**
17 * @brief Determine if this is a HB or PHYP TI event
18 *
19 * Use the TI info data area to determine if this is either a HB or a PHYP
20 * TI event then handle the event.
21 *
Ben Tynerf5210bb2021-01-05 12:58:10 -060022 * @param i_tiDataArea pointer to the TI info data
Ben Tyner8c5e4f42020-10-28 11:11:55 -050023 */
Ben Tyner792f32f2020-06-02 08:50:47 -050024int tiHandler(TiDataArea* i_tiDataArea)
Ben Tyner9ae5ca42020-02-28 13:13:50 -060025{
Ben Tynere4f5dbe2020-10-19 07:19:33 -050026 int rc = RC_SUCCESS;
Ben Tyner9ae5ca42020-02-28 13:13:50 -060027
Ben Tyner8c5e4f42020-10-28 11:11:55 -050028 // check TI data area if it is available
Ben Tynere4f5dbe2020-10-19 07:19:33 -050029 if (nullptr != i_tiDataArea)
Ben Tyner792f32f2020-06-02 08:50:47 -050030 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050031 // HB v. PHYP TI logic: Only hosboot will fill in hbTerminateType
Ben Tyner8882c322021-02-05 12:13:21 -060032 // and it will be non-zero. Only hostboot will fill out source and
33 // it it will be non-zero. Only PHYP will fill in srcFormat and it
34 // will be non-zero.
Ben Tyner8c5e4f42020-10-28 11:11:55 -050035 if ((0 == i_tiDataArea->hbTerminateType) &&
36 (0 == i_tiDataArea->source) && (0 != i_tiDataArea->srcFormat))
Ben Tynere4f5dbe2020-10-19 07:19:33 -050037 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050038 handlePhypTi(i_tiDataArea);
Ben Tynere4f5dbe2020-10-19 07:19:33 -050039 }
40 else
41 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050042 handleHbTi(i_tiDataArea);
Ben Tynere4f5dbe2020-10-19 07:19:33 -050043 }
Ben Tyner8c5e4f42020-10-28 11:11:55 -050044 }
45 else
46 {
Ben Tyner29651ef2021-02-08 10:51:03 -060047 // TI data was not available This should not happen since we provide
48 // a default TI info in the case where get TI info was not successful.
Ben Tyner7a0dd542021-02-12 09:33:44 -060049 eventAttentionFail((int)AttnSection::tiHandler | ATTN_INFO_NULL);
Ben Tyner29651ef2021-02-08 10:51:03 -060050 rc = RC_NOT_HANDLED;
Ben Tynere4f5dbe2020-10-19 07:19:33 -050051 }
Ben Tyner40717722020-09-23 09:43:20 -050052
Ben Tyner8c5e4f42020-10-28 11:11:55 -050053 return rc;
54}
Ben Tynere4f5dbe2020-10-19 07:19:33 -050055
Ben Tyner8c5e4f42020-10-28 11:11:55 -050056/**
Ben Tyner8c5e4f42020-10-28 11:11:55 -050057 * @brief Handle a PHYP terminate immediate special attention
58 *
59 * The TI info data area will contain information pertaining to the TI
60 * condition. We will wither quiesce the host or initiate a MPIPL depending
61 * depending on the auto reboot configuration. We will also create a PEL which
62 * will contain the TI info data and FFDC data captured in the system journal.
63 *
64 * @param i_tiDataArea pointer to TI information filled in by hostboot
65 */
66void handlePhypTi(TiDataArea* i_tiDataArea)
67{
68 trace<level::INFO>("PHYP TI");
69
Ben Tyner8c5e4f42020-10-28 11:11:55 -050070 // gather additional data for PEL
71 std::map<std::string, std::string> tiAdditionalData;
Ben Tynere4f5dbe2020-10-19 07:19:33 -050072
Ben Tyner8c5e4f42020-10-28 11:11:55 -050073 if (nullptr != i_tiDataArea)
74 {
75 parsePhypOpalTiInfo(tiAdditionalData, i_tiDataArea);
Ben Tyner29651ef2021-02-08 10:51:03 -060076
77 tiAdditionalData["Subsystem"] =
78 std::to_string(static_cast<uint8_t>(pel::SubsystemID::hypervisor));
79
Ben Tyner9d4f91c2021-02-09 08:27:58 -060080 // Copy all ascii src chars to additional data
81 char srcChar[33]; // 32 ascii chars + null term
82 memcpy(srcChar, &(i_tiDataArea->asciiData0), 32);
83 srcChar[32] = 0;
Ben Tyner29651ef2021-02-08 10:51:03 -060084 tiAdditionalData["SrcAscii"] = std::string{srcChar};
85
86 // TI event
87 eventTerminate(tiAdditionalData, (char*)i_tiDataArea);
Ben Tyner8c5e4f42020-10-28 11:11:55 -050088 }
Ben Tyner29651ef2021-02-08 10:51:03 -060089 else
90 {
91 // TI data was not available This should not happen since we provide
92 // a default TI info in the case where get TI info was not successful.
Ben Tyner7a0dd542021-02-12 09:33:44 -060093 eventAttentionFail((int)AttnSection::handlePhypTi | ATTN_INFO_NULL);
Ben Tyner29651ef2021-02-08 10:51:03 -060094 }
Ben Tyner063f6bd2021-03-26 07:45:56 -050095
96 // We are finished creating the event log entries so transition host to
97 // the required state.
98 if (autoRebootEnabled())
99 {
100 // If autoreboot is enabled we will start crash (mpipl) mode target
101 transitionHost(HostState::Crash);
102 }
103 else
104 {
105 // If autoreboot is disabled we will quiesce the host
106 transitionHost(HostState::Quiesce);
107 }
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500108}
109
110/**
111 * @brief Handle a hostboot terminate immediate special attention
112 *
113 * The TI info data area will contain information pertaining to the TI
114 * condition. The course of action to take regarding the host state will
115 * depend on the contents of the TI info data area. We will also create a
116 * PEL containing the TI info data and FFDC data captured in the system
117 * journal.
118 *
119 * @param i_tiDataArea pointer to TI information filled in by hostboot
120 */
121void handleHbTi(TiDataArea* i_tiDataArea)
122{
123 trace<level::INFO>("HB TI");
124
125 bool hbDumpRequested = true; // HB dump is common case
126 bool generatePel = true; // assume PEL will be created
127 bool terminateHost = true; // transition host state
128
129 // handle specific hostboot reason codes
130 if (nullptr != i_tiDataArea)
131 {
Ben Tyner8882c322021-02-05 12:13:21 -0600132 std::stringstream ss; // stream object for tracing
133 std::string strobj; // string object for tracing
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500134
135 switch (i_tiDataArea->hbTerminateType)
136 {
137 case TI_WITH_PLID:
138 case TI_WITH_EID:
Ben Tyner8882c322021-02-05 12:13:21 -0600139
140 // trace this value
141 ss.str(std::string()); // empty the stream
142 ss.clear(); // clear the stream
143 ss << "TI with PLID/EID: " << std::hex << std::showbase
144 << std::setw(8) << std::setfill('0')
145 << be32toh(i_tiDataArea->asciiData1);
146 strobj = ss.str();
147 trace<level::INFO>(strobj.c_str());
148
149 // see if HB dump is requested
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500150 if (0 == i_tiDataArea->hbDumpFlag)
151 {
152 hbDumpRequested = false; // no HB dump requested
153 }
154 break;
155 case TI_WITH_SRC:
Ben Tyner8882c322021-02-05 12:13:21 -0600156 // Reason code is byte 2 and 3 of 4 byte srcWord12HbWord0
157 uint16_t reasonCode = be32toh(i_tiDataArea->srcWord12HbWord0);
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500158
Ben Tyner8882c322021-02-05 12:13:21 -0600159 // trace this value
160 ss.str(std::string()); // empty the stream
161 ss.clear(); // clear the stream
162 ss << "TI with SRC: " << std::hex << std::showbase
163 << std::setw(4) << std::setfill('0') << (int)reasonCode;
164 strobj = ss.str();
165 trace<level::INFO>(strobj.c_str());
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500166
Ben Tyner8882c322021-02-05 12:13:21 -0600167 switch (reasonCode)
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500168 {
169 case HB_SRC_SHUTDOWN_REQUEST:
170 trace<level::INFO>("shutdown request");
Ben Tyner8882c322021-02-05 12:13:21 -0600171 generatePel = false;
172 hbDumpRequested = false;
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500173 break;
174 case HB_SRC_KEY_TRANSITION:
Ben Tyner8882c322021-02-05 12:13:21 -0600175 // Note: Should never see this so lets leave
176 // hbDumpRequested == true so we can figure out why
177 // we are here.
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500178 trace<level::INFO>("key transition");
179 terminateHost = false;
180 break;
181 case HB_SRC_INSUFFICIENT_HW:
182 trace<level::INFO>("insufficient hardware");
183 break;
184 case HB_SRC_TPM_FAIL:
185 trace<level::INFO>("TPM fail");
186 break;
187 case HB_SRC_ROM_VERIFY:
188 trace<level::INFO>("ROM verify");
189 break;
190 case HB_SRC_EXT_MISMATCH:
191 trace<level::INFO>("EXT mismatch");
192 break;
193 case HB_SRC_ECC_UE:
194 trace<level::INFO>("ECC UE");
195 break;
196 case HB_SRC_UNSUPPORTED_MODE:
197 trace<level::INFO>("unsupported mode");
198 break;
199 case HB_SRC_UNSUPPORTED_SFCRANGE:
200 trace<level::INFO>("unsupported SFC range");
201 break;
202 case HB_SRC_PARTITION_TABLE:
203 trace<level::INFO>("partition table invalid");
204 break;
205 case HB_SRC_UNSUPPORTED_HARDWARE:
206 trace<level::INFO>("unsupported hardware");
207 break;
208 case HB_SRC_PNOR_CORRUPTION:
209 trace<level::INFO>("PNOR corruption");
210 break;
211 default:
212 trace<level::INFO>("reason: other");
213 }
214
Ben Tyner5c5db652021-02-22 18:22:35 -0600215 break; // case TI_WITH_SRC
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500216 }
217 }
218
Ben Tyner5c5db652021-02-22 18:22:35 -0600219 if (true == generatePel)
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500220 {
Ben Tyner5c5db652021-02-22 18:22:35 -0600221 if (nullptr != i_tiDataArea)
Ben Tyner29651ef2021-02-08 10:51:03 -0600222 {
Ben Tyner5c5db652021-02-22 18:22:35 -0600223 // gather additional data for PEL
224 std::map<std::string, std::string> tiAdditionalData;
225
226 parseHbTiInfo(tiAdditionalData, i_tiDataArea);
227
Ben Tyner29651ef2021-02-08 10:51:03 -0600228 tiAdditionalData["Subsystem"] = std::to_string(
229 static_cast<uint8_t>(pel::SubsystemID::hostboot));
230
Ben Tyner5c5db652021-02-22 18:22:35 -0600231 // Translate hex src value to ascii. This results in an 8
232 // character SRC (hostboot SRC is 32 bits)
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600233 std::stringstream src;
Ben Tyner4bbcb382021-02-22 09:29:00 -0600234 src << std::setw(8) << std::setfill('0') << std::uppercase
235 << std::hex << be32toh(i_tiDataArea->srcWord12HbWord0);
Ben Tyner9d4f91c2021-02-09 08:27:58 -0600236 tiAdditionalData["SrcAscii"] = src.str();
Ben Tyner29651ef2021-02-08 10:51:03 -0600237
Ben Tyner5c5db652021-02-22 18:22:35 -0600238 // Request dump after generating event log?
239 tiAdditionalData["Dump"] =
240 (true == hbDumpRequested) ? "true" : "false";
241
242 // Generate event log
Ben Tyner29651ef2021-02-08 10:51:03 -0600243 eventTerminate(tiAdditionalData, (char*)i_tiDataArea);
244 }
Ben Tyner5c5db652021-02-22 18:22:35 -0600245 else
246 {
247 // TI data was not available This should not happen.
248 eventAttentionFail((int)AttnSection::handleHbTi | ATTN_INFO_NULL);
249 }
Ben Tyner40717722020-09-23 09:43:20 -0500250 }
Ben Tyner063f6bd2021-03-26 07:45:56 -0500251
252 if (true == terminateHost)
253 {
Ben Tyner5c5db652021-02-22 18:22:35 -0600254 transitionHost(HostState::Quiesce);
Ben Tyner063f6bd2021-03-26 07:45:56 -0500255 }
Ben Tyner40717722020-09-23 09:43:20 -0500256}
257
258/** @brief Parse the TI info data area into map as PHYP/OPAL data */
259void parsePhypOpalTiInfo(std::map<std::string, std::string>& i_map,
260 TiDataArea* i_tiDataArea)
261{
Ben Tyner1c4b02e2020-11-09 14:00:29 -0600262 if (nullptr == i_tiDataArea)
263 {
264 return;
265 }
266
Ben Tyner40717722020-09-23 09:43:20 -0500267 std::stringstream ss;
268
Ben Tynerfeeea832021-04-06 10:08:11 -0500269 ss << "0x00 TI Area Valid:" << std::setw(2) << std::setfill('0') << std::hex
270 << (int)i_tiDataArea->tiAreaValid << ":";
271 ss << "0x01 Command:" << std::setw(2) << std::setfill('0') << std::hex
272 << (int)i_tiDataArea->command << ":";
273 ss << "0x02 Num. Data Bytes:" << std::setw(4) << std::setfill('0')
274 << std::hex << be16toh(i_tiDataArea->numDataBytes) << ":";
275 ss << "0x04 Reserved:" << std::setw(2) << std::setfill('0') << std::hex
276 << (int)i_tiDataArea->reserved1 << ":";
277 ss << "0x06 HWDump Type:" << std::setw(4) << std::setfill('0') << std::hex
278 << be16toh(i_tiDataArea->hardwareDumpType) << ":";
279 ss << "0x08 SRC Format:" << std::setw(2) << std::setfill('0') << std::hex
280 << (int)i_tiDataArea->srcFormat << ":";
281 ss << "0x09 SRC Flags:" << std::setw(2) << std::setfill('0') << std::hex
282 << (int)i_tiDataArea->srcFlags << ":";
283 ss << "0x0a Num. ASCII Words:" << std::setw(2) << std::setfill('0')
284 << std::hex << (int)i_tiDataArea->numAsciiWords << ":";
285 ss << "0x0b Num. Hex Words:" << std::setw(2) << std::setfill('0')
286 << std::hex << (int)i_tiDataArea->numHexWords << ":";
287 ss << "0x0e Length of SRC:" << std::setw(4) << std::setfill('0') << std::hex
288 << be16toh(i_tiDataArea->lenSrc) << ":";
289 ss << "0x10 SRC Word 12:" << std::setw(8) << std::setfill('0') << std::hex
290 << be32toh(i_tiDataArea->srcWord12HbWord0) << ":";
291 ss << "0x14 SRC Word 13:" << std::setw(8) << std::setfill('0') << std::hex
292 << be32toh(i_tiDataArea->srcWord13HbWord2) << ":";
293 ss << "0x18 SRC Word 14:" << std::setw(8) << std::setfill('0') << std::hex
294 << be32toh(i_tiDataArea->srcWord14HbWord3) << ":";
295 ss << "0x1c SRC Word 15:" << std::setw(8) << std::setfill('0') << std::hex
296 << be32toh(i_tiDataArea->srcWord15HbWord4) << ":";
297 ss << "0x20 SRC Word 16:" << std::setw(8) << std::setfill('0') << std::hex
298 << be32toh(i_tiDataArea->srcWord16HbWord5) << ":";
299 ss << "0x24 SRC Word 17:" << std::setw(8) << std::setfill('0') << std::hex
300 << be32toh(i_tiDataArea->srcWord17HbWord6) << ":";
301 ss << "0x28 SRC Word 18:" << std::setw(8) << std::setfill('0') << std::hex
302 << be32toh(i_tiDataArea->srcWord18HbWord7) << ":";
303 ss << "0x2c SRC Word 19:" << std::setw(8) << std::setfill('0') << std::hex
304 << be32toh(i_tiDataArea->srcWord19HbWord8) << ":";
305 ss << "0x30 ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
306 << be32toh(i_tiDataArea->asciiData0) << ":";
307 ss << "0x34 ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
308 << be32toh(i_tiDataArea->asciiData1) << ":";
309 ss << "0x38 ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
310 << be32toh(i_tiDataArea->asciiData2) << ":";
311 ss << "0x3c ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
312 << be32toh(i_tiDataArea->asciiData3) << ":";
313 ss << "0x40 ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
314 << be32toh(i_tiDataArea->asciiData4) << ":";
315 ss << "0x44 ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
316 << be32toh(i_tiDataArea->asciiData5) << ":";
317 ss << "0x48 ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
318 << be32toh(i_tiDataArea->asciiData6) << ":";
319 ss << "0x4c ASCII Data:" << std::setw(8) << std::setfill('0') << std::hex
320 << be32toh(i_tiDataArea->asciiData7) << ":";
321 ss << "0x50 Location:" << std::setw(2) << std::setfill('0') << std::hex
322 << (int)i_tiDataArea->location << ":";
323 ss << "0x51 Code Sections:" << std::setw(2) << std::setfill('0') << std::hex
324 << (int)i_tiDataArea->codeSection << ":";
325 ss << "0x52 Additional Size:" << std::setw(2) << std::setfill('0')
326 << std::hex << (int)i_tiDataArea->additionalSize << ":";
327 ss << "0x53 Additional Data:" << std::setw(2) << std::setfill('0')
328 << std::hex << (int)i_tiDataArea->andData;
Ben Tyner40717722020-09-23 09:43:20 -0500329
330 std::string key, value;
331 char delim = ':';
332
333 while (std::getline(ss, key, delim))
334 {
335 std::getline(ss, value, delim);
336 i_map[key] = value;
337 }
338}
339
340/** @brief Parse the TI info data area into map as hostboot data */
341void parseHbTiInfo(std::map<std::string, std::string>& i_map,
342 TiDataArea* i_tiDataArea)
343{
Ben Tyner1c4b02e2020-11-09 14:00:29 -0600344 if (nullptr == i_tiDataArea)
345 {
346 return;
347 }
348
Ben Tyner40717722020-09-23 09:43:20 -0500349 std::stringstream ss;
350
Ben Tynerfeeea832021-04-06 10:08:11 -0500351 ss << "0x00 TI Area Valid:" << std::setw(2) << std::setfill('0') << std::hex
352 << (int)i_tiDataArea->tiAreaValid << ":";
353 ss << "0x04 Reserved:" << std::setw(2) << std::setfill('0') << std::hex
354 << (int)i_tiDataArea->reserved1 << ":";
355 ss << "0x05 HB_Term. Type:" << std::setw(2) << std::setfill('0') << std::hex
356 << (int)i_tiDataArea->hbTerminateType << ":";
357 ss << "0x0c HB Dump Flag:" << std::setw(2) << std::setfill('0') << std::hex
358 << (int)i_tiDataArea->hbDumpFlag << ":";
359 ss << "0x0d Source:" << std::setw(2) << std::setfill('0') << std::hex
360 << (int)i_tiDataArea->source << ":";
361 ss << "0x10 HB Word 0:" << std::setw(8) << std::setfill('0') << std::hex
362 << be32toh(i_tiDataArea->srcWord12HbWord0) << ":";
363 ss << "0x14 HB Word 2:" << std::setw(8) << std::setfill('0') << std::hex
364 << be32toh(i_tiDataArea->srcWord13HbWord2) << ":";
365 ss << "0x18 HB Word 3:" << std::setw(8) << std::setfill('0') << std::hex
366 << be32toh(i_tiDataArea->srcWord14HbWord3) << ":";
367 ss << "0x1c HB Word 4:" << std::setw(8) << std::setfill('0') << std::hex
368 << be32toh(i_tiDataArea->srcWord15HbWord4) << ":";
369 ss << "0x20 HB Word 5:" << std::setw(8) << std::setfill('0') << std::hex
370 << be32toh(i_tiDataArea->srcWord16HbWord5) << ":";
371 ss << "0x24 HB Word 6:" << std::setw(8) << std::setfill('0') << std::hex
372 << be32toh(i_tiDataArea->srcWord17HbWord6) << ":";
373 ss << "0x28 HB Word 7:" << std::setw(8) << std::setfill('0') << std::hex
374 << be32toh(i_tiDataArea->srcWord18HbWord7) << ":";
375 ss << "0x2c HB Word 8:" << std::setw(8) << std::setfill('0') << std::hex
376 << be32toh(i_tiDataArea->srcWord19HbWord8) << ":";
377 ss << "0x30 error_data:" << std::setw(8) << std::setfill('0') << std::hex
378 << be32toh(i_tiDataArea->asciiData0) << ":";
379 ss << "0x34 EID:" << std::setw(8) << std::setfill('0') << std::hex
380 << be32toh(i_tiDataArea->asciiData1);
Ben Tyner40717722020-09-23 09:43:20 -0500381
382 std::string key, value;
383 char delim = ':';
384
385 while (std::getline(ss, key, delim))
386 {
387 std::getline(ss, value, delim);
388 i_map[key] = value;
389 }
390}
391
392/** @brief Read state of autoreboot propertyi via dbus */
Ben Tynerff17f962020-09-23 08:21:19 -0500393bool autoRebootEnabled()
394{
395 // Use dbus get-property interface to read the autoreboot property
396 auto bus = sdbusplus::bus::new_system();
397 auto method =
398 bus.new_method_call("xyz.openbmc_project.Settings",
399 "/xyz/openbmc_project/control/host0/auto_reboot",
400 "org.freedesktop.DBus.Properties", "Get");
Ben Tyner40717722020-09-23 09:43:20 -0500401
Ben Tynerff17f962020-09-23 08:21:19 -0500402 method.append("xyz.openbmc_project.Control.Boot.RebootPolicy",
403 "AutoReboot");
Ben Tyner40717722020-09-23 09:43:20 -0500404
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500405 bool autoReboot = false; // assume autoreboot attribute not available
406
Ben Tynerff17f962020-09-23 08:21:19 -0500407 try
408 {
409 auto reply = bus.call(method);
Ben Tyner40717722020-09-23 09:43:20 -0500410
Ben Tynerff17f962020-09-23 08:21:19 -0500411 std::variant<bool> result;
412 reply.read(result);
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500413 autoReboot = std::get<bool>(result);
Ben Tynerff17f962020-09-23 08:21:19 -0500414 }
Ben Tyner6764d702021-02-12 09:17:23 -0600415 catch (const sdbusplus::exception::SdBusError& e)
Ben Tynerff17f962020-09-23 08:21:19 -0500416 {
Ben Tyner6764d702021-02-12 09:17:23 -0600417 trace<level::INFO>("autoRebootEnbabled exception");
418 std::string traceMsg = std::string(e.what(), maxTraceLen);
419 trace<level::ERROR>(traceMsg.c_str());
Ben Tynerff17f962020-09-23 08:21:19 -0500420 }
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500421
422 return autoReboot;
Ben Tynerff17f962020-09-23 08:21:19 -0500423}
Ben Tyner40717722020-09-23 09:43:20 -0500424
Ben Tyner5c5db652021-02-22 18:22:35 -0600425/**
426 * Callback for dump request properties change signal monitor
427 *
428 * @param[in] i_msg Dbus message from the dbus match infrastructure
429 * @param[in] i_path The object path we are monitoring
430 * @param[out] o_inProgress Used to break out of our dbus wait loop
431 * @reutn Always non-zero indicating no error, no cascading callbacks
432 */
433uint dumpStatusChanged(sdbusplus::message::message& i_msg, std::string i_path,
434 bool& o_inProgress)
435{
436 // reply (msg) will be a property change message
437 std::string interface;
438 std::map<std::string, std::variant<std::string, uint8_t>> property;
439 i_msg.read(interface, property);
440
441 // looking for property Status changes
442 std::string propertyType = "Status";
443 auto dumpStatus = property.find(propertyType);
444
445 if (dumpStatus != property.end())
446 {
447 const std::string* status =
448 std::get_if<std::string>(&(dumpStatus->second));
449
450 if ((nullptr != status) && ("xyz.openbmc_project.Common.Progress."
451 "OperationStatus.InProgress" != *status))
452 {
453 // dump is done, trace some info and change in progress flag
454 trace<level::INFO>(i_path.c_str());
455 trace<level::INFO>((*status).c_str());
456 o_inProgress = false;
457 }
458 }
459
460 return 1; // non-negative return code for successful callback
461}
462
463/**
464 * Register a callback for dump progress status changes
465 *
466 * @param[in] i_path The object path of the dump to monitor
467 */
468void monitorDump(const std::string& i_path)
469{
470 bool inProgress = true; // callback will update this
471
472 // setup the signal match rules and callback
473 std::string matchInterface = "xyz.openbmc_project.Common.Progress";
474 auto bus = sdbusplus::bus::new_system();
475
476 std::unique_ptr<sdbusplus::bus::match_t> match =
477 std::make_unique<sdbusplus::bus::match_t>(
478 bus,
479 sdbusplus::bus::match::rules::propertiesChanged(
480 i_path.c_str(), matchInterface.c_str()),
481 [&](auto& msg) {
482 return dumpStatusChanged(msg, i_path, inProgress);
483 });
484
485 // wait for dump status to be completed (complete == true)
486 trace<level::INFO>("hbdump requested");
487 while (true == inProgress)
488 {
489 bus.wait(0);
490 bus.process_discard();
491 }
492 trace<level::INFO>("hbdump completed");
493}
494
495/** Request a dump from the dump manager */
496void requestDump(const uint32_t logId)
497{
498 constexpr auto path = "/org/openpower/dump";
499 constexpr auto interface = "xyz.openbmc_project.Dump.Create";
500 constexpr auto function = "CreateDump";
501
502 sdbusplus::message::message method;
503
504 if (0 == dbusMethod(path, interface, function, method))
505 {
506 try
507 {
508 // dbus call arguments
509 std::map<std::string, std::string> createParams;
510 createParams["com.ibm.Dump.Create.CreateParameters.DumpType"] =
511 "com.ibm.Dump.Create.DumpType.Hostboot";
512 createParams["com.ibm.Dump.Create.CreateParameters.ErrorLogId"] =
513 std::to_string(logId);
514 method.append(createParams);
515
516 // using system dbus
517 auto bus = sdbusplus::bus::new_system();
518 auto response = bus.call(method);
519
520 // reply will be type dbus::ObjectPath
521 sdbusplus::message::object_path reply;
522 response.read(reply);
523
524 // monitor dump progress
525 monitorDump(reply);
526 }
527 catch (const sdbusplus::exception::SdBusError& e)
528 {
529 trace<level::ERROR>("requestDump exception");
530 std::string traceMsg = std::string(e.what(), maxTraceLen);
531 trace<level::ERROR>(traceMsg.c_str());
532 }
533 }
534}
535
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600536} // namespace attn