blob: a8daedb637dfc8fb8e82dfebd198a4c594047bc9 [file] [log] [blame]
Ben Tynerb797b3e2020-06-29 10:12:05 -05001#include <attn/attn_handler.hpp>
2#include <attn/attn_logging.hpp>
3#include <attn/ti_handler.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06004#include <sdbusplus/bus.hpp>
Ben Tynerff17f962020-09-23 08:21:19 -05005#include <sdbusplus/exception.hpp>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06006
Ben Tyner40717722020-09-23 09:43:20 -05007#include <iomanip>
8#include <iostream>
9
Ben Tyner9ae5ca42020-02-28 13:13:50 -060010namespace attn
11{
12
Ben Tyner8c5e4f42020-10-28 11:11:55 -050013/**
14 * @brief Determine if this is a HB or PHYP TI event
15 *
16 * Use the TI info data area to determine if this is either a HB or a PHYP
17 * TI event then handle the event.
18 *
19 * @param i_tiDataArea pointer to the TI infor data
20 */
Ben Tyner792f32f2020-06-02 08:50:47 -050021int tiHandler(TiDataArea* i_tiDataArea)
Ben Tyner9ae5ca42020-02-28 13:13:50 -060022{
Ben Tynere4f5dbe2020-10-19 07:19:33 -050023 int rc = RC_SUCCESS;
Ben Tyner9ae5ca42020-02-28 13:13:50 -060024
Ben Tyner8c5e4f42020-10-28 11:11:55 -050025 // check TI data area if it is available
Ben Tynere4f5dbe2020-10-19 07:19:33 -050026 if (nullptr != i_tiDataArea)
Ben Tyner792f32f2020-06-02 08:50:47 -050027 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050028 // HB v. PHYP TI logic: Only hosboot will fill in hbTerminateType
29 // and it will be non-zero. Only hostboot will fill out source and it
30 // it will be non-zero. Only PHYP will fill in srcFormat and it will
31 // be non-zero.
32 // source and only PHYP will fill in srcFormat.
33 if ((0 == i_tiDataArea->hbTerminateType) &&
34 (0 == i_tiDataArea->source) && (0 != i_tiDataArea->srcFormat))
Ben Tynere4f5dbe2020-10-19 07:19:33 -050035 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050036 handlePhypTi(i_tiDataArea);
Ben Tynere4f5dbe2020-10-19 07:19:33 -050037 }
38 else
39 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050040 handleHbTi(i_tiDataArea);
Ben Tynere4f5dbe2020-10-19 07:19:33 -050041 }
Ben Tyner8c5e4f42020-10-28 11:11:55 -050042 }
43 else
44 {
45 // TI data was not available, assume PHYP TI for now. When a host state
46 // management interface becomes availabe we may be able to make a more
47 // informed decision here.
48 handlePhypTi(i_tiDataArea);
Ben Tynere4f5dbe2020-10-19 07:19:33 -050049 }
Ben Tyner40717722020-09-23 09:43:20 -050050
Ben Tyner8c5e4f42020-10-28 11:11:55 -050051 return rc;
52}
Ben Tynere4f5dbe2020-10-19 07:19:33 -050053
Ben Tyner8c5e4f42020-10-28 11:11:55 -050054/**
55 * @brief Transition the host state
56 *
57 * We will transition the host state by starting the appropriate dbus target.
58 *
59 * @param i_target the dbus target to start
60 */
61void transitionHost(const char* i_target)
62{
63 // We will be transitioning host by starting appropriate dbus target
Ben Tynere4f5dbe2020-10-19 07:19:33 -050064 auto bus = sdbusplus::bus::new_system();
65 auto method = bus.new_method_call(
66 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
67 "org.freedesktop.systemd1.Manager", "StartUnit");
68
Ben Tyner8c5e4f42020-10-28 11:11:55 -050069 method.append(i_target); // target unit to start
70 method.append("replace"); // mode = replace conflicting queued jobs
Ben Tyner9ae5ca42020-02-28 13:13:50 -060071
Ben Tyner8c5e4f42020-10-28 11:11:55 -050072 trace<level::INFO>(i_target);
73
74 bus.call_noreply(method); // start the service
75}
76
77/**
78 * @brief Handle a PHYP terminate immediate special attention
79 *
80 * The TI info data area will contain information pertaining to the TI
81 * condition. We will wither quiesce the host or initiate a MPIPL depending
82 * depending on the auto reboot configuration. We will also create a PEL which
83 * will contain the TI info data and FFDC data captured in the system journal.
84 *
85 * @param i_tiDataArea pointer to TI information filled in by hostboot
86 */
87void handlePhypTi(TiDataArea* i_tiDataArea)
88{
89 trace<level::INFO>("PHYP TI");
90
91 if (autoRebootEnabled())
92 {
93 // If autoreboot is enabled we will start diagnostic mode target
94 // which will ultimately mpipl the host.
95 transitionHost("obmc-host-diagnostic-mode@0.target");
Ben Tyner792f32f2020-06-02 08:50:47 -050096 }
Ben Tyner40717722020-09-23 09:43:20 -050097 else
98 {
Ben Tyner8c5e4f42020-10-28 11:11:55 -050099 // If autoreboot is disabled we will quiesce the host
100 transitionHost("obmc-host-quiesce@0.target");
Ben Tyner40717722020-09-23 09:43:20 -0500101 }
Ben Tyner792f32f2020-06-02 08:50:47 -0500102
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500103 // gather additional data for PEL
104 std::map<std::string, std::string> tiAdditionalData;
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500105
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500106 if (nullptr != i_tiDataArea)
107 {
108 parsePhypOpalTiInfo(tiAdditionalData, i_tiDataArea);
109 parseRawTiInfo(tiAdditionalData, i_tiDataArea);
110 }
111
112 eventTerminate(tiAdditionalData); // generate PEL
113}
114
115/**
116 * @brief Handle a hostboot terminate immediate special attention
117 *
118 * The TI info data area will contain information pertaining to the TI
119 * condition. The course of action to take regarding the host state will
120 * depend on the contents of the TI info data area. We will also create a
121 * PEL containing the TI info data and FFDC data captured in the system
122 * journal.
123 *
124 * @param i_tiDataArea pointer to TI information filled in by hostboot
125 */
126void handleHbTi(TiDataArea* i_tiDataArea)
127{
128 trace<level::INFO>("HB TI");
129
130 bool hbDumpRequested = true; // HB dump is common case
131 bool generatePel = true; // assume PEL will be created
132 bool terminateHost = true; // transition host state
133
134 // handle specific hostboot reason codes
135 if (nullptr != i_tiDataArea)
136 {
137 std::stringstream ss;
138 ss << std::hex << std::showbase;
139
140 switch (i_tiDataArea->hbTerminateType)
141 {
142 case TI_WITH_PLID:
143 case TI_WITH_EID:
144 ss << "TI with PLID/EID: " << be32toh(i_tiDataArea->asciiData1);
145 trace<level::INFO>(ss.str().c_str());
146 if (0 == i_tiDataArea->hbDumpFlag)
147 {
148 hbDumpRequested = false; // no HB dump requested
149 }
150 break;
151 case TI_WITH_SRC:
152 // SRC is byte 2 and 3 of 4 byte srcWord12HbWord0
153 uint16_t hbSrc = be32toh(i_tiDataArea->srcWord12HbWord0);
154
155 // trace some info
156 ss << "TI with SRC: " << (int)hbSrc;
157 trace<level::INFO>(ss.str().c_str());
158 ss.str(std::string()); // clear stream
159
160 switch (hbSrc)
161 {
162 case HB_SRC_SHUTDOWN_REQUEST:
163 trace<level::INFO>("shutdown request");
164 generatePel = false;
165 break;
166 case HB_SRC_KEY_TRANSITION:
167 trace<level::INFO>("key transition");
168 terminateHost = false;
169 break;
170 case HB_SRC_INSUFFICIENT_HW:
171 trace<level::INFO>("insufficient hardware");
172 break;
173 case HB_SRC_TPM_FAIL:
174 trace<level::INFO>("TPM fail");
175 break;
176 case HB_SRC_ROM_VERIFY:
177 trace<level::INFO>("ROM verify");
178 break;
179 case HB_SRC_EXT_MISMATCH:
180 trace<level::INFO>("EXT mismatch");
181 break;
182 case HB_SRC_ECC_UE:
183 trace<level::INFO>("ECC UE");
184 break;
185 case HB_SRC_UNSUPPORTED_MODE:
186 trace<level::INFO>("unsupported mode");
187 break;
188 case HB_SRC_UNSUPPORTED_SFCRANGE:
189 trace<level::INFO>("unsupported SFC range");
190 break;
191 case HB_SRC_PARTITION_TABLE:
192 trace<level::INFO>("partition table invalid");
193 break;
194 case HB_SRC_UNSUPPORTED_HARDWARE:
195 trace<level::INFO>("unsupported hardware");
196 break;
197 case HB_SRC_PNOR_CORRUPTION:
198 trace<level::INFO>("PNOR corruption");
199 break;
200 default:
201 trace<level::INFO>("reason: other");
202 }
203
204 break;
205 }
206 }
207
208 if (true == terminateHost)
209 {
210 // if hostboot dump is requested initiate dump
211 if (hbDumpRequested)
212 {
213 // Until HB dump support available just quiesce the host - once
214 // dump support is available the dump component will transition
215 // (ipl/halt) the host.
216 transitionHost("obmc-host-quiesce@0.target");
217 }
218 else
219 {
220 // Quiese the host - when the host is quiesced it will either
221 // "halt" or IPL depending on autoreboot setting.
222 transitionHost("obmc-host-quiesce@0.target");
223 }
224 }
225
226 // gather additional data for PEL
227 std::map<std::string, std::string> tiAdditionalData;
228
229 if (nullptr != i_tiDataArea)
230 {
231 parseHbTiInfo(tiAdditionalData, i_tiDataArea);
232 parseRawTiInfo(tiAdditionalData, i_tiDataArea);
233 }
234
235 if (true == generatePel)
236 {
237 eventTerminate(tiAdditionalData); // generate PEL
238 }
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600239}
240
Ben Tyner40717722020-09-23 09:43:20 -0500241/** @brief Parse the TI info data area into map as raw 32-bit fields */
242void parseRawTiInfo(std::map<std::string, std::string>& i_map,
243 TiDataArea* i_buffer)
244{
Ben Tyner1c4b02e2020-11-09 14:00:29 -0600245 if (nullptr == i_buffer)
246 {
247 return;
248 }
Ben Tyner40717722020-09-23 09:43:20 -0500249
250 uint32_t* tiDataArea = (uint32_t*)i_buffer;
251 std::stringstream ss;
252
253 ss << std::hex << std::setfill('0');
254 ss << "raw:";
255 while (tiDataArea <= (uint32_t*)((char*)i_buffer + sizeof(TiDataArea)))
256 {
257 ss << std::setw(8) << std::endl << be32toh(*tiDataArea);
258 tiDataArea++;
259 }
260
261 std::string key, value;
262 char delim = ':';
263
264 while (std::getline(ss, key, delim))
265 {
266 std::getline(ss, value, delim);
267 i_map[key] = value;
268 }
269}
270
271/** @brief Parse the TI info data area into map as PHYP/OPAL data */
272void parsePhypOpalTiInfo(std::map<std::string, std::string>& i_map,
273 TiDataArea* i_tiDataArea)
274{
Ben Tyner1c4b02e2020-11-09 14:00:29 -0600275 if (nullptr == i_tiDataArea)
276 {
277 return;
278 }
279
Ben Tyner40717722020-09-23 09:43:20 -0500280 std::stringstream ss;
281
282 ss << std::hex << std::showbase;
283 ss << "0x00 TI Area Valid:" << (int)i_tiDataArea->tiAreaValid << ":";
284 ss << "0x01 Command:" << (int)i_tiDataArea->command << ":";
285 ss << "0x02 Num. Data Bytes:" << be16toh(i_tiDataArea->numDataBytes) << ":";
286 ss << "0x04 Reserved:" << (int)i_tiDataArea->reserved1 << ":";
287 ss << "0x06 HWDump Type:" << be16toh(i_tiDataArea->hardwareDumpType) << ":";
288 ss << "0x08 SRC Format:" << (int)i_tiDataArea->srcFormat << ":";
289 ss << "0x09 SRC Flags:" << (int)i_tiDataArea->srcFlags << ":";
290 ss << "0x0a Num. ASCII Words:" << (int)i_tiDataArea->numAsciiWords << ":";
291 ss << "0x0b Num. Hex Words:" << (int)i_tiDataArea->numHexWords << ":";
292 ss << "0x0e Length of SRC:" << be16toh(i_tiDataArea->lenSrc) << ":";
293 ss << "0x10 SRC Word 12:" << be32toh(i_tiDataArea->srcWord12HbWord0) << ":";
294 ss << "0x14 SRC Word 13:" << be32toh(i_tiDataArea->srcWord13HbWord2) << ":";
295 ss << "0x18 SRC Word 14:" << be32toh(i_tiDataArea->srcWord14HbWord3) << ":";
296 ss << "0x1c SRC Word 15:" << be32toh(i_tiDataArea->srcWord15HbWord4) << ":";
297 ss << "0x20 SRC Word 16:" << be32toh(i_tiDataArea->srcWord16HbWord5) << ":";
298 ss << "0x24 SRC Word 17:" << be32toh(i_tiDataArea->srcWord17HbWord6) << ":";
299 ss << "0x28 SRC Word 18:" << be32toh(i_tiDataArea->srcWord18HbWord7) << ":";
300 ss << "0x2c SRC Word 19:" << be32toh(i_tiDataArea->srcWord19HbWord8) << ":";
301 ss << "0x30 ASCII Data:" << be32toh(i_tiDataArea->asciiData0) << ":";
302 ss << "0x34 ASCII Data:" << be32toh(i_tiDataArea->asciiData1) << ":";
303 ss << "0x38 ASCII Data:" << be32toh(i_tiDataArea->asciiData2) << ":";
304 ss << "0x3c ASCII Data:" << be32toh(i_tiDataArea->asciiData3) << ":";
305 ss << "0x40 ASCII Data:" << be32toh(i_tiDataArea->asciiData4) << ":";
306 ss << "0x44 ASCII Data:" << be32toh(i_tiDataArea->asciiData5) << ":";
307 ss << "0x48 ASCII Data:" << be32toh(i_tiDataArea->asciiData6) << ":";
308 ss << "0x4c ASCII Data:" << be32toh(i_tiDataArea->asciiData7) << ":";
309 ss << "0x50 Location:" << (int)i_tiDataArea->location << ":";
310 ss << "0x51 Code Sections:" << (int)i_tiDataArea->codeSection << ":";
311 ss << "0x52 Additional Size:" << (int)i_tiDataArea->additionalSize << ":";
312 ss << "0x53 Additional Data:" << (int)i_tiDataArea->andData;
313
314 std::string key, value;
315 char delim = ':';
316
317 while (std::getline(ss, key, delim))
318 {
319 std::getline(ss, value, delim);
320 i_map[key] = value;
321 }
322}
323
324/** @brief Parse the TI info data area into map as hostboot data */
325void parseHbTiInfo(std::map<std::string, std::string>& i_map,
326 TiDataArea* i_tiDataArea)
327{
Ben Tyner1c4b02e2020-11-09 14:00:29 -0600328 if (nullptr == i_tiDataArea)
329 {
330 return;
331 }
332
Ben Tyner40717722020-09-23 09:43:20 -0500333 std::stringstream ss;
334
335 ss << std::hex << std::showbase;
336 ss << "0x00 TI Area Valid:" << (int)i_tiDataArea->tiAreaValid << ":";
337 ss << "0x04 Reserved:" << (int)i_tiDataArea->reserved1 << ":";
338 ss << "0x05 HB_Term. Type:" << (int)i_tiDataArea->hbTerminateType << ":";
339 ss << "0x0c HB Dump Flag:" << (int)i_tiDataArea->hbDumpFlag << ":";
340 ss << "0x0d Source:" << (int)i_tiDataArea->source << ":";
341 ss << "0x10 HB Word 0:" << be32toh(i_tiDataArea->srcWord12HbWord0) << ":";
342 ss << "0x14 HB Word 2:" << be32toh(i_tiDataArea->srcWord13HbWord2) << ":";
343 ss << "0x18 HB Word 3:" << be32toh(i_tiDataArea->srcWord14HbWord3) << ":";
344 ss << "0x1c HB Word 4:" << be32toh(i_tiDataArea->srcWord15HbWord4) << ":";
345 ss << "0x20 HB Word 5:" << be32toh(i_tiDataArea->srcWord16HbWord5) << ":";
346 ss << "0x24 HB Word 6:" << be32toh(i_tiDataArea->srcWord17HbWord6) << ":";
347 ss << "0x28 HB Word 7:" << be32toh(i_tiDataArea->srcWord18HbWord7) << ":";
348 ss << "0x2c HB Word 8:" << be32toh(i_tiDataArea->srcWord19HbWord8) << ":";
349 ss << "0x30 error_data:" << be32toh(i_tiDataArea->asciiData0) << ":";
350 ss << "0x34 EID:" << be32toh(i_tiDataArea->asciiData1);
351
352 std::string key, value;
353 char delim = ':';
354
355 while (std::getline(ss, key, delim))
356 {
357 std::getline(ss, value, delim);
358 i_map[key] = value;
359 }
360}
361
362/** @brief Read state of autoreboot propertyi via dbus */
Ben Tynerff17f962020-09-23 08:21:19 -0500363bool autoRebootEnabled()
364{
365 // Use dbus get-property interface to read the autoreboot property
366 auto bus = sdbusplus::bus::new_system();
367 auto method =
368 bus.new_method_call("xyz.openbmc_project.Settings",
369 "/xyz/openbmc_project/control/host0/auto_reboot",
370 "org.freedesktop.DBus.Properties", "Get");
Ben Tyner40717722020-09-23 09:43:20 -0500371
Ben Tynerff17f962020-09-23 08:21:19 -0500372 method.append("xyz.openbmc_project.Control.Boot.RebootPolicy",
373 "AutoReboot");
Ben Tyner40717722020-09-23 09:43:20 -0500374
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500375 bool autoReboot = false; // assume autoreboot attribute not available
376
Ben Tynerff17f962020-09-23 08:21:19 -0500377 try
378 {
379 auto reply = bus.call(method);
Ben Tyner40717722020-09-23 09:43:20 -0500380
Ben Tynerff17f962020-09-23 08:21:19 -0500381 std::variant<bool> result;
382 reply.read(result);
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500383 autoReboot = std::get<bool>(result);
Ben Tynerff17f962020-09-23 08:21:19 -0500384 }
385 catch (const sdbusplus::exception::SdBusError& ec)
386 {
Ben Tynerff17f962020-09-23 08:21:19 -0500387 std::string traceMessage =
388 "Error in AutoReboot Get: " + std::string(ec.what());
389 trace<level::INFO>(traceMessage.c_str());
Ben Tynerff17f962020-09-23 08:21:19 -0500390 }
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500391
392 return autoReboot;
Ben Tynerff17f962020-09-23 08:21:19 -0500393}
Ben Tyner40717722020-09-23 09:43:20 -0500394
Ben Tyner9ae5ca42020-02-28 13:13:50 -0600395} // namespace attn