blob: a0e428e4aca22fc584a3747f7bc4555fcffec808 [file] [log] [blame]
Jayanth Othayothb1eda6a2021-06-28 00:26:30 -05001extern "C"
2{
Ben Tyner792f32f2020-06-02 08:50:47 -05003#include <libpdbg.h>
Jayanth Othayothb1eda6a2021-06-28 00:26:30 -05004#include <libpdbg_sbe.h>
5}
Ben Tyner792f32f2020-06-02 08:50:47 -05006
Zane Shelleya06dcf82021-11-03 10:23:21 -05007#include <config.h>
8
Ben Tynerb9715172021-09-29 08:46:19 -05009#ifdef CONFIG_PHAL_API
10#include <libphal.H>
11#endif
12
Ben Tyner0205f3b2020-02-24 10:24:47 -060013#include <analyzer/analyzer_main.hpp>
Ben Tynerb797b3e2020-06-29 10:12:05 -050014#include <attn/attention.hpp>
Ben Tynerbcf65a82020-12-01 08:46:36 -060015#include <attn/attn_common.hpp>
Ben Tynerb797b3e2020-06-29 10:12:05 -050016#include <attn/attn_config.hpp>
Ben Tyner4bbcb382021-02-22 09:29:00 -060017#include <attn/attn_dbus.hpp>
Ben Tynerb797b3e2020-06-29 10:12:05 -050018#include <attn/attn_handler.hpp>
19#include <attn/attn_logging.hpp>
20#include <attn/bp_handler.hpp>
21#include <attn/ti_handler.hpp>
Ben Tynerbcf65a82020-12-01 08:46:36 -060022#include <attn/vital_handler.hpp>
Ben Tynerfe2c50d2021-07-23 13:38:53 -050023#include <util/dbus.hpp>
Ben Tyner76e52f62022-02-01 10:46:44 -060024#include <util/ffdc_file.hpp>
Ben Tyner6a69e6e2022-04-05 23:18:29 -050025#include <util/pdbg.hpp>
Ben Tyner76e52f62022-02-01 10:46:44 -060026#include <util/trace.hpp>
Ben Tyneref320152020-01-09 10:31:23 -060027
Ben Tynerb481d902020-03-05 10:24:23 -060028#include <algorithm>
Ben Tyneref320152020-01-09 10:31:23 -060029#include <iomanip>
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050030#include <map>
Ben Tyner9ae5ca42020-02-28 13:13:50 -060031#include <sstream>
Ben Tynerb481d902020-03-05 10:24:23 -060032#include <vector>
Ben Tyneref320152020-01-09 10:31:23 -060033
34namespace attn
35{
Ben Tyneref320152020-01-09 10:31:23 -060036/**
Ben Tyneref320152020-01-09 10:31:23 -060037 * @brief Handle checkstop attention
38 *
Ben Tynerb481d902020-03-05 10:24:23 -060039 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050040 * @return 0 indicates that the checkstop attention was successfully handled
41 * 1 indicates that the checkstop attention was NOT successfully
42 * handled.
Ben Tyneref320152020-01-09 10:31:23 -060043 */
Ben Tynerb481d902020-03-05 10:24:23 -060044int handleCheckstop(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060045
46/**
47 * @brief Handle special attention
48 *
Ben Tynerb481d902020-03-05 10:24:23 -060049 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050050 * @return 0 indicates that the special attention was successfully handled
51 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -060052 */
Ben Tynerb481d902020-03-05 10:24:23 -060053int handleSpecial(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060054
Ben Tynerfb190542020-11-06 09:27:56 -060055/** @brief Determine if attention is active and not masked */
Ben Tyner1965e502020-11-20 10:32:24 -060056bool activeAttn(uint32_t i_val, uint32_t i_mask, uint32_t i_attn);
Ben Tynerfb190542020-11-06 09:27:56 -060057
Ben Tynerb9715172021-09-29 08:46:19 -050058#ifdef CONFIG_PHAL_API
59/** @brief Handle phal sbe exception */
60void phalSbeExceptionHandler(openpower::phal::exception::SbeError& e,
Ben Tyner76e52f62022-02-01 10:46:44 -060061 uint32_t chipPosition, uint32_t command);
Ben Tynerb9715172021-09-29 08:46:19 -050062#endif
63
64/** @brief Get static TI info data based on host state */
65void getStaticTiInfo(uint8_t*& tiInfoPtr);
66
67/** @brief Check if TI info data is valid */
68bool tiInfoValid(uint8_t* tiInfo);
69
Ben Tyner6a69e6e2022-04-05 23:18:29 -050070/** @brief Clear attention interrupts */
71void clearAttnInterrupts();
72
Ben Tyneref320152020-01-09 10:31:23 -060073/**
Ben Tyneref320152020-01-09 10:31:23 -060074 * @brief The main attention handler logic
Ben Tyner970fd4f2020-02-19 13:46:42 -060075 *
76 * @param i_breakpoints true = breakpoint special attn handling enabled
Ben Tyneref320152020-01-09 10:31:23 -060077 */
Ben Tyner3fb52e52020-03-31 10:10:07 -050078void attnHandler(Config* i_config)
Ben Tyneref320152020-01-09 10:31:23 -060079{
austinfcuid28d5f82022-04-28 16:20:39 -050080 // Check if enClrAttnIntr is enabled
81 if (true == i_config->getFlag(enClrAttnIntr))
82 {
83 // Clear attention interrupts that may still be active (MPIPL)
84 clearAttnInterrupts();
85 }
Ben Tyner6a69e6e2022-04-05 23:18:29 -050086
Ben Tynerb481d902020-03-05 10:24:23 -060087 // Vector of active attentions to be handled
88 std::vector<Attention> active_attentions;
89
Ben Tyneref320152020-01-09 10:31:23 -060090 uint32_t isr_val, isr_mask;
Ben Tyneref320152020-01-09 10:31:23 -060091
92 // loop through processors looking for active attentions
austinfcuibfa831a2022-01-26 15:37:07 -060093 trace::inf("Attention handler started");
Ben Tyner117af992020-05-22 13:32:11 -050094
Ben Tyneref320152020-01-09 10:31:23 -060095 pdbg_target* target;
Ben Tyner5e622d82020-09-11 10:10:24 -050096 pdbg_for_each_class_target("proc", target)
Ben Tyneref320152020-01-09 10:31:23 -060097 {
98 if (PDBG_TARGET_ENABLED == pdbg_target_probe(target))
99 {
Zane Shelleya79f6c82021-01-12 16:38:49 -0600100 auto proc = pdbg_target_index(target); // get processor number
Ben Tyneref320152020-01-09 10:31:23 -0600101
Ben Tynerb83c8522020-11-20 10:45:26 -0600102 // Use PIB target to determine if a processor is enabled
Ben Tyner5e622d82020-09-11 10:10:24 -0500103 char path[16];
Ben Tynerb83c8522020-11-20 10:45:26 -0600104 sprintf(path, "/proc%d/pib", proc);
Ben Tyner8882c322021-02-05 12:13:21 -0600105 pdbg_target* pibTarget = pdbg_target_from_path(nullptr, path);
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500106
Ben Tynerb83c8522020-11-20 10:45:26 -0600107 // sanity check
Ben Tyner8882c322021-02-05 12:13:21 -0600108 if (nullptr == pibTarget)
Ben Tynerb83c8522020-11-20 10:45:26 -0600109 {
austinfcuibfa831a2022-01-26 15:37:07 -0600110 trace::inf("pib path or target not found");
Ben Tynerb83c8522020-11-20 10:45:26 -0600111 continue;
112 }
113
Ben Tyner8882c322021-02-05 12:13:21 -0600114 // check if pib target is enabled
115 if (PDBG_TARGET_ENABLED == pdbg_target_probe(pibTarget))
Ben Tyneref320152020-01-09 10:31:23 -0600116 {
Ben Tynerb83c8522020-11-20 10:45:26 -0600117 // The processor FSI target is required for CFAM read
118 sprintf(path, "/proc%d/fsi", proc);
Ben Tyner8882c322021-02-05 12:13:21 -0600119 pdbg_target* fsiTarget = pdbg_target_from_path(nullptr, path);
Ben Tynerb83c8522020-11-20 10:45:26 -0600120
121 // sanity check
Ben Tyner8882c322021-02-05 12:13:21 -0600122 if (nullptr == fsiTarget)
Ben Tynerb83c8522020-11-20 10:45:26 -0600123 {
austinfcuibfa831a2022-01-26 15:37:07 -0600124 trace::inf("fsi path or target not found");
Ben Tynerb83c8522020-11-20 10:45:26 -0600125 continue;
126 }
127
Ben Tyner8882c322021-02-05 12:13:21 -0600128 // trace the proc number
austinfcuibfa831a2022-01-26 15:37:07 -0600129 trace::inf("proc: %u", proc);
Ben Tyner1965e502020-11-20 10:32:24 -0600130
Ben Tyner5adc96e2020-11-20 10:54:12 -0600131 isr_val = 0xffffffff; // invalid isr value
132
Ben Tyner5e622d82020-09-11 10:10:24 -0500133 // get active attentions on processor
Ben Tyner8882c322021-02-05 12:13:21 -0600134 if (RC_SUCCESS != fsi_read(fsiTarget, 0x1007, &isr_val))
Ben Tyneref320152020-01-09 10:31:23 -0600135 {
Ben Tynerfb190542020-11-06 09:27:56 -0600136 // log cfam read error
austinfcuibfa831a2022-01-26 15:37:07 -0600137 trace::err("cfam read 0x1007 FAILED");
Ben Tyner7a0dd542021-02-12 09:33:44 -0600138 eventAttentionFail((int)AttnSection::attnHandler |
139 ATTN_PDBG_CFAM);
Ben Tyneref320152020-01-09 10:31:23 -0600140 }
Ben Tyner5adc96e2020-11-20 10:54:12 -0600141 else if (0xffffffff == isr_val)
142 {
austinfcuibfa831a2022-01-26 15:37:07 -0600143 trace::err("cfam read 0x1007 INVALID");
Ben Tyner5adc96e2020-11-20 10:54:12 -0600144 continue;
145 }
Ben Tyneref320152020-01-09 10:31:23 -0600146 else
147 {
Ben Tyner8882c322021-02-05 12:13:21 -0600148 // trace isr value
austinfcuibfa831a2022-01-26 15:37:07 -0600149 trace::inf("cfam 0x1007 = 0x%08x", isr_val);
Ben Tyner1965e502020-11-20 10:32:24 -0600150
Ben Tyner5adc96e2020-11-20 10:54:12 -0600151 isr_mask = 0xffffffff; // invalid isr mask
152
Ben Tyner5e622d82020-09-11 10:10:24 -0500153 // get interrupt enabled special attentions mask
Ben Tyner8882c322021-02-05 12:13:21 -0600154 if (RC_SUCCESS != fsi_read(fsiTarget, 0x100d, &isr_mask))
Ben Tyneref320152020-01-09 10:31:23 -0600155 {
Ben Tynerfb190542020-11-06 09:27:56 -0600156 // log cfam read error
austinfcuibfa831a2022-01-26 15:37:07 -0600157 trace::err("cfam read 0x100d FAILED");
Ben Tyner7a0dd542021-02-12 09:33:44 -0600158 eventAttentionFail((int)AttnSection::attnHandler |
159 ATTN_PDBG_CFAM);
Ben Tyneref320152020-01-09 10:31:23 -0600160 }
Ben Tyner5adc96e2020-11-20 10:54:12 -0600161 else if (0xffffffff == isr_mask)
162 {
austinfcuibfa831a2022-01-26 15:37:07 -0600163 trace::err("cfam read 0x100d INVALID");
Ben Tyner5adc96e2020-11-20 10:54:12 -0600164 continue;
165 }
Ben Tyner5e622d82020-09-11 10:10:24 -0500166 else
167 {
Ben Tyner8882c322021-02-05 12:13:21 -0600168 // trace true mask
austinfcuibfa831a2022-01-26 15:37:07 -0600169 trace::inf("cfam 0x100d = 0x%08x", isr_mask);
Ben Tyner1965e502020-11-20 10:32:24 -0600170
Ben Tynerfb190542020-11-06 09:27:56 -0600171 // SBE vital attention active and not masked?
Ben Tyner1965e502020-11-20 10:32:24 -0600172 if (true == activeAttn(isr_val, isr_mask, SBE_ATTN))
Ben Tyner5e622d82020-09-11 10:10:24 -0500173 {
174 active_attentions.emplace_back(Attention::Vital,
175 handleVital, target,
176 i_config);
177 }
178
Ben Tynerfb190542020-11-06 09:27:56 -0600179 // Checkstop attention active and not masked?
180 if (true ==
Ben Tyner1965e502020-11-20 10:32:24 -0600181 activeAttn(isr_val, isr_mask, CHECKSTOP_ATTN))
Ben Tyner5e622d82020-09-11 10:10:24 -0500182 {
183 active_attentions.emplace_back(Attention::Checkstop,
184 handleCheckstop,
185 target, i_config);
186 }
187
Ben Tynerfb190542020-11-06 09:27:56 -0600188 // Special attention active and not masked?
Ben Tyner1965e502020-11-20 10:32:24 -0600189 if (true == activeAttn(isr_val, isr_mask, SPECIAL_ATTN))
Ben Tyner5e622d82020-09-11 10:10:24 -0500190 {
191 active_attentions.emplace_back(Attention::Special,
192 handleSpecial,
193 target, i_config);
194 }
195 } // cfam 0x100d valid
196 } // cfam 0x1007 valid
Ben Tyner8882c322021-02-05 12:13:21 -0600197 } // fsi target enabled
198 } // pib target enabled
Ben Tyner5e622d82020-09-11 10:10:24 -0500199 } // next processor
Ben Tyneref320152020-01-09 10:31:23 -0600200
Ben Tynerb481d902020-03-05 10:24:23 -0600201 // convert to heap, highest priority is at front
202 if (!std::is_heap(active_attentions.begin(), active_attentions.end()))
203 {
204 std::make_heap(active_attentions.begin(), active_attentions.end());
205 }
206
207 // call the attention handler until one is handled or all were attempted
208 while (false == active_attentions.empty())
209 {
210 // handle highest priority attention, done if successful
211 if (RC_SUCCESS == active_attentions.front().handle())
212 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500213 // an attention was handled so we are done
Ben Tynerb481d902020-03-05 10:24:23 -0600214 break;
215 }
216
217 // move attention to back of vector
218 std::pop_heap(active_attentions.begin(), active_attentions.end());
219
220 // remove attention from vector
221 active_attentions.pop_back();
222 }
Ben Tyneref320152020-01-09 10:31:23 -0600223}
224
225/**
Ben Tyneref320152020-01-09 10:31:23 -0600226 * @brief Handle checkstop attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500227 *
228 * @param i_attention Attention object
229 * @return 0 indicates that the checkstop attention was successfully handled
230 * 1 indicates that the checkstop attention was NOT successfully
231 * handled.
Ben Tyneref320152020-01-09 10:31:23 -0600232 */
Ben Tynerb481d902020-03-05 10:24:23 -0600233int handleCheckstop(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600234{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500235 int rc = RC_SUCCESS; // assume checkstop handled
Ben Tyneref320152020-01-09 10:31:23 -0600236
austinfcuibfa831a2022-01-26 15:37:07 -0600237 trace::inf("checkstop handler started");
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500238
Ben Tynerb8335562021-07-16 12:43:52 -0500239 // capture some additional data for logs/traces
240 addHbStatusRegs();
241
Ben Tyner3fb52e52020-03-31 10:10:07 -0500242 // if checkstop handling enabled, handle checkstop attention
243 if (false == (i_attention->getConfig()->getFlag(enCheckstop)))
244 {
austinfcuibfa831a2022-01-26 15:37:07 -0600245 trace::inf("Checkstop handling disabled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500246 }
247 else
248 {
Ben Tyner2b26b2b2022-12-15 15:42:02 -0600249 // check for power fault before starting analyses
Ben Tyner07ebb9b2021-12-01 12:16:24 -0600250 sleepSeconds(POWER_FAULT_WAIT);
Ben Tyner2b26b2b2022-12-15 15:42:02 -0600251 if (!util::dbus::powerFault())
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500252 {
Ben Tyner2b26b2b2022-12-15 15:42:02 -0600253 // Look for any attentions found in hardware. This will generate and
254 // commit a PEL if any errors are found.
255 DumpParameters dumpParameters;
256 auto logid = analyzer::analyzeHardware(
257 analyzer::AnalysisType::SYSTEM_CHECKSTOP, dumpParameters);
258 if (0 == logid)
259 {
260 // A PEL should exist for a checkstop attention.
261 rc = RC_ANALYZER_ERROR;
262 }
263 else
264 {
265 requestDump(logid, dumpParameters);
266 util::dbus::transitionHost(util::dbus::HostState::Quiesce);
267 }
Ben Tyner7029e522021-08-09 19:18:24 -0500268 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500269 }
Ben Tyneref320152020-01-09 10:31:23 -0600270
Ben Tyneref320152020-01-09 10:31:23 -0600271 return rc;
272}
273
274/**
275 * @brief Handle special attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500276 *
277 * @param i_attention Attention object
278 * @return 0 indicates that the special attention was successfully handled
279 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600280 */
Ben Tynerb481d902020-03-05 10:24:23 -0600281int handleSpecial(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600282{
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500283 int rc = RC_SUCCESS; // assume special attention handled
Ben Tyneref320152020-01-09 10:31:23 -0600284
Ben Tynerfb190542020-11-06 09:27:56 -0600285 // The TI info chipop will give us a pointer to the TI info data
Ben Tyner98430b32020-08-19 19:14:02 -0500286 uint8_t* tiInfo = nullptr; // ptr to TI info data
287 uint32_t tiInfoLen = 0; // length of TI info data
288 pdbg_target* attnProc = i_attention->getTarget(); // proc with attention
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500289
Ben Tyner29651ef2021-02-08 10:51:03 -0600290 bool tiInfoStatic = false; // assume TI info was provided (not created)
291
Ben Tynerb9715172021-09-29 08:46:19 -0500292 // need proc target to get dynamic TI info
293 if (nullptr != attnProc)
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500294 {
Ben Tynerb9715172021-09-29 08:46:19 -0500295#ifdef CONFIG_PHAL_API
austinfcuibfa831a2022-01-26 15:37:07 -0600296 trace::inf("using libphal to get TI info");
Ben Tynerb9715172021-09-29 08:46:19 -0500297
298 // phal library uses proc target for get ti info
299 if (PDBG_TARGET_ENABLED == pdbg_target_probe(attnProc))
300 {
301 try
302 {
303 // get dynamic TI info
304 openpower::phal::sbe::getTiInfo(attnProc, &tiInfo, &tiInfoLen);
305 }
Ben Tyner76e52f62022-02-01 10:46:44 -0600306 catch (openpower::phal::exception::SbeError& sbeError)
Ben Tynerb9715172021-09-29 08:46:19 -0500307 {
308 // library threw an exception
Ben Tyner76e52f62022-02-01 10:46:44 -0600309 // note: phal::sbe::getTiInfo = command class | command ==
310 // 0xa900 | 0x04 = 0xa904. The sbe fifo command class and
Ben Tyner6a69e6e2022-04-05 23:18:29 -0500311 // commands are defined in the sbefifo library source code
312 // but do not seem to be exported/installed for consumption
Ben Tyner76e52f62022-02-01 10:46:44 -0600313 // externally.
Ben Tynerb9715172021-09-29 08:46:19 -0500314 uint32_t procNum = pdbg_target_index(attnProc);
Ben Tyner76e52f62022-02-01 10:46:44 -0600315 phalSbeExceptionHandler(sbeError, procNum, 0xa904);
Ben Tynerb9715172021-09-29 08:46:19 -0500316 }
317 }
318#else
austinfcuibfa831a2022-01-26 15:37:07 -0600319 trace::inf("using libpdbg to get TI info");
Ben Tynerb9715172021-09-29 08:46:19 -0500320
321 // pdbg library uses pib target for get ti info
Ben Tyner98430b32020-08-19 19:14:02 -0500322 char path[16];
323 sprintf(path, "/proc%d/pib", pdbg_target_index(attnProc));
324 pdbg_target* tiInfoTarget = pdbg_target_from_path(nullptr, path);
325
326 if (nullptr != tiInfoTarget)
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500327 {
Ben Tyner98430b32020-08-19 19:14:02 -0500328 if (PDBG_TARGET_ENABLED == pdbg_target_probe(tiInfoTarget))
329 {
Ben Tyner98430b32020-08-19 19:14:02 -0500330 sbe_mpipl_get_ti_info(tiInfoTarget, &tiInfo, &tiInfoLen);
Ben Tyner98430b32020-08-19 19:14:02 -0500331 }
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500332 }
Ben Tynerb9715172021-09-29 08:46:19 -0500333#endif
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500334 }
Ben Tyneref320152020-01-09 10:31:23 -0600335
Ben Tynerb9715172021-09-29 08:46:19 -0500336 // dynamic TI info is not available
337 if (nullptr == tiInfo)
Ben Tyner970fd4f2020-02-19 13:46:42 -0600338 {
austinfcuibfa831a2022-01-26 15:37:07 -0600339 trace::inf("TI info data ptr is invalid");
Ben Tynerb9715172021-09-29 08:46:19 -0500340 getStaticTiInfo(tiInfo);
341 tiInfoStatic = true;
Ben Tyner3fb52e52020-03-31 10:10:07 -0500342 }
Ben Tyner0fe5df42020-12-03 08:57:17 -0600343
Ben Tynerb9715172021-09-29 08:46:19 -0500344 // check TI info for validity and handle
345 if (true == tiInfoValid(tiInfo))
346 {
347 // TI info is valid handle TI if support enabled
348 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
349 {
350 // Call TI special attention handler
351 rc = tiHandler((TiDataArea*)tiInfo);
352 }
353 }
354 else
Ben Tyner3fb52e52020-03-31 10:10:07 -0500355 {
austinfcuibfa831a2022-01-26 15:37:07 -0600356 trace::inf("TI info NOT valid");
Ben Tyner98430b32020-08-19 19:14:02 -0500357
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500358 // if configured to handle TI as default special attention
Ben Tynerfe156492021-04-08 07:28:13 -0500359 if (i_attention->getConfig()->getFlag(dfltTi))
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500360 {
Ben Tynerfe156492021-04-08 07:28:13 -0500361 // TI handling may be disabled
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500362 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
363 {
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500364 // Call TI special attention handler
Ben Tynerb9715172021-09-29 08:46:19 -0500365 rc = tiHandler((TiDataArea*)tiInfo);
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500366 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500367 }
Ben Tynerb9715172021-09-29 08:46:19 -0500368 // configured to handle breakpoint as default special attention
Ben Tynerfe156492021-04-08 07:28:13 -0500369 else
370 {
371 // breakpoint handling may be disabled
372 if (true == (i_attention->getConfig()->getFlag(enBreakpoints)))
373 {
374 // Call the breakpoint special attention handler
375 rc = bpHandler();
376 }
377 }
Ben Tyner970fd4f2020-02-19 13:46:42 -0600378 }
Ben Tyneref320152020-01-09 10:31:23 -0600379
Ben Tynerb9715172021-09-29 08:46:19 -0500380 // release TI data buffer if not ours
381 if (false == tiInfoStatic)
Ben Tyner792f32f2020-06-02 08:50:47 -0500382 {
Ben Tynerb9715172021-09-29 08:46:19 -0500383 // sanity check
384 if (nullptr != tiInfo)
385 {
386 free(tiInfo);
387 }
Ben Tyner792f32f2020-06-02 08:50:47 -0500388 }
389
Ben Tynerb9715172021-09-29 08:46:19 -0500390 // trace non-successful exit condition
Ben Tyner3fb52e52020-03-31 10:10:07 -0500391 if (RC_SUCCESS != rc)
392 {
austinfcuibfa831a2022-01-26 15:37:07 -0600393 trace::inf("Special attn not handled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500394 }
Ben Tyneref320152020-01-09 10:31:23 -0600395
396 return rc;
397}
398
Ben Tynerfb190542020-11-06 09:27:56 -0600399/**
400 * @brief Determine if attention is active and not masked
401 *
402 * Determine whether an attention needs to be handled and trace details of
403 * attention type and whether it is masked or not.
404 *
405 * @param i_val attention status register
406 * @param i_mask attention true mask register
407 * @param i_attn attention type
408 * @param i_proc processor associated with registers
409 *
410 * @return true if attention is active and not masked, otherwise false
411 */
Ben Tyner1965e502020-11-20 10:32:24 -0600412bool activeAttn(uint32_t i_val, uint32_t i_mask, uint32_t i_attn)
Ben Tynerfb190542020-11-06 09:27:56 -0600413{
Zane Shelley9fb657f2021-01-12 15:30:58 -0600414 bool rc = false; // assume attn masked and/or inactive
Ben Tynerfb190542020-11-06 09:27:56 -0600415
416 // if attention active
417 if (0 != (i_val & i_attn))
418 {
austinfcuibfa831a2022-01-26 15:37:07 -0600419 std::string msg;
Ben Tynerfb190542020-11-06 09:27:56 -0600420
Zane Shelley9fb657f2021-01-12 15:30:58 -0600421 bool validAttn = true; // known attention type
422
Ben Tynerfb190542020-11-06 09:27:56 -0600423 switch (i_attn)
424 {
425 case SBE_ATTN:
austinfcuibfa831a2022-01-26 15:37:07 -0600426 msg = "SBE attn";
Ben Tynerfb190542020-11-06 09:27:56 -0600427 break;
428 case CHECKSTOP_ATTN:
austinfcuibfa831a2022-01-26 15:37:07 -0600429 msg = "Checkstop attn";
Ben Tynerfb190542020-11-06 09:27:56 -0600430 break;
431 case SPECIAL_ATTN:
austinfcuibfa831a2022-01-26 15:37:07 -0600432 msg = "Special attn";
Ben Tynerfb190542020-11-06 09:27:56 -0600433 break;
434 default:
austinfcuibfa831a2022-01-26 15:37:07 -0600435 msg = "Unknown attn";
Ben Tynerfb190542020-11-06 09:27:56 -0600436 validAttn = false;
437 }
438
439 // see if attention is masked
440 if (true == validAttn)
441 {
442 if (0 != (i_mask & i_attn))
443 {
444 rc = true; // attention active and not masked
445 }
446 else
447 {
austinfcuibfa831a2022-01-26 15:37:07 -0600448 msg += " masked";
Ben Tynerfb190542020-11-06 09:27:56 -0600449 }
450 }
451
austinfcuibfa831a2022-01-26 15:37:07 -0600452 trace::inf(msg.c_str()); // commit trace stream
Ben Tynerfb190542020-11-06 09:27:56 -0600453 }
454
455 return rc;
456}
Ben Tynerb9715172021-09-29 08:46:19 -0500457
458#ifdef CONFIG_PHAL_API
Ben Tyner76e52f62022-02-01 10:46:44 -0600459
Ben Tynerb9715172021-09-29 08:46:19 -0500460/**
461 * @brief Handle phal sbe exception
462 *
463 * @param[in] e - exception object
464 * @param[in] procNum - processor number associated with sbe exception
465 */
Ben Tyner76e52f62022-02-01 10:46:44 -0600466void phalSbeExceptionHandler(openpower::phal::exception::SbeError& sbeError,
467 uint32_t chipPosition, uint32_t command)
Ben Tynerb9715172021-09-29 08:46:19 -0500468{
Ben Tyner76e52f62022-02-01 10:46:44 -0600469 trace::err("Attention handler phal exception handler");
Ben Tynerb9715172021-09-29 08:46:19 -0500470
Ben Tyner76e52f62022-02-01 10:46:44 -0600471 // Trace exception details
472 trace::err(sbeError.what());
473
474 // Create event log entry with SBE FFDC data if provided
475 auto fd = sbeError.getFd();
476 if (fd > 0)
Ben Tynerb9715172021-09-29 08:46:19 -0500477 {
Ben Tyner76e52f62022-02-01 10:46:44 -0600478 trace::err("SBE FFDC data is available");
479
480 // FFDC parser expects chip position and command (command class |
481 // command) to be in the additional data.
482 std::map<std::string, std::string> additionalData = {
483 {"SRC6", std::to_string((chipPosition << 16) | command)}};
484
Ben Tyner6a69e6e2022-04-05 23:18:29 -0500485 // See phosphor-logging/extensions/openpower-pels/README.md, "Self
486 // Boot Engine(SBE) First Failure Data Capture(FFDC)" - SBE FFDC
487 // file type is 0xCB, version is 0x01.
Ben Tyner76e52f62022-02-01 10:46:44 -0600488 std::vector<util::FFDCTuple> ffdc{util::FFDCTuple{
489 util::FFDCFormat::Custom, static_cast<uint8_t>(0xCB),
490 static_cast<uint8_t>(0x01), fd}};
491
492 // Create event log entry with FFDC data
Ben Tyner13159682022-02-16 14:55:38 -0600493 util::dbus::createPel("org.open_power.Processor.Error.SbeChipOpFailure",
494 levelPelError, additionalData, ffdc);
Ben Tynerb9715172021-09-29 08:46:19 -0500495 }
496}
497#endif
498
499/**
500 * @brief Get static TI info data based on host state
501 *
502 * @param[out] tiInfo - pointer to static TI info data
503 */
504void getStaticTiInfo(uint8_t*& tiInfo)
505{
506 util::dbus::HostRunningState runningState = util::dbus::hostRunningState();
507
508 // assume host state is unknown
509 std::string stateString = "host state unknown";
510
511 if ((util::dbus::HostRunningState::Started == runningState) ||
512 (util::dbus::HostRunningState::Unknown == runningState))
513 {
514 if (util::dbus::HostRunningState::Started == runningState)
515 {
516 stateString = "host started";
517 }
518 tiInfo = (uint8_t*)defaultPhypTiInfo;
519 }
520 else
521 {
522 stateString = "host not started";
523 tiInfo = (uint8_t*)defaultHbTiInfo;
524 }
525
526 // trace host state
austinfcuibfa831a2022-01-26 15:37:07 -0600527 trace::inf(stateString.c_str());
Ben Tynerb9715172021-09-29 08:46:19 -0500528}
529
530/**
531 * @brief Check if TI info data is valid
532 *
533 * @param[in] tiInfo - pointer to TI info data
534 * @return true if TI info data is valid, else false
535 */
536bool tiInfoValid(uint8_t* tiInfo)
537{
538 bool tiInfoValid = false; // assume TI info invalid
539
540 // TI info data[0] non-zero indicates TI info valid (usually)
541 if ((nullptr != tiInfo) && (0 != tiInfo[0]))
542 {
543 TiDataArea* tiDataArea = (TiDataArea*)tiInfo;
544
Ben Tynerb9715172021-09-29 08:46:19 -0500545 // trace a few known TI data area values
Ben Tyner535a8d42022-03-08 18:07:14 -0600546 trace::inf("TI data command = 0x%02x", tiDataArea->command);
Ben Tynerb9715172021-09-29 08:46:19 -0500547
548 // Another check for valid TI Info since it has been seen that
549 // tiInfo[0] != 0 but TI info is not valid
550 if (0xa1 == tiDataArea->command)
551 {
552 tiInfoValid = true;
553
554 // trace some more data since TI info appears valid
Ben Tyner535a8d42022-03-08 18:07:14 -0600555 trace::inf("TI data term-type = 0x%02x",
austinfcuibfa831a2022-01-26 15:37:07 -0600556 tiDataArea->hbTerminateType);
Ben Tynerb9715172021-09-29 08:46:19 -0500557
Ben Tyner535a8d42022-03-08 18:07:14 -0600558 trace::inf("TI data SRC format = 0x%02x", tiDataArea->srcFormat);
Ben Tynerb9715172021-09-29 08:46:19 -0500559
Ben Tyner535a8d42022-03-08 18:07:14 -0600560 trace::inf("TI data source = 0x%02x", tiDataArea->source);
Ben Tynerb9715172021-09-29 08:46:19 -0500561 }
562 }
563
564 return tiInfoValid;
565}
566
Ben Tyner6a69e6e2022-04-05 23:18:29 -0500567/**
568 * @brief Clear attention interrupts
569 *
570 * The attention interrupts are sticky and may still be set (MPIPL) even if
571 * there are no active attentions. If there is an active attention then
572 * clearing the associated interrupt will have no effect.
573 */
574void clearAttnInterrupts()
575{
576 trace::inf("Clearing attention interrupts");
577
578 // loop through processors clearing attention interrupts
579 pdbg_target* procTarget;
580 pdbg_for_each_class_target("proc", procTarget)
581 {
582 // active processors only
583 if (PDBG_TARGET_ENABLED !=
584 pdbg_target_probe(util::pdbg::getPibTrgt(procTarget)))
585 {
586 continue;
587 }
588
589 // get cfam is an fsi read
590 pdbg_target* fsiTarget = util::pdbg::getFsiTrgt(procTarget);
591 uint32_t int_val;
592
593 // get attention interrupts on processor
594 if (RC_SUCCESS == fsi_read(fsiTarget, 0x100b, &int_val))
595 {
596 // trace int value
597 trace::inf("cfam 0x100b = 0x%08x", int_val);
598
599 int_val &= ~(ANY_ATTN | CHECKSTOP_ATTN | SPECIAL_ATTN |
600 RECOVERABLE_ATTN | SBE_ATTN);
601
602 // clear attention interrupts on processor
603 if (RC_SUCCESS != fsi_write(fsiTarget, 0x100b, int_val))
604 {
605 // log cfam write error
606 trace::err("cfam write 0x100b FAILED");
607 }
608 }
609 else
610 {
611 // log cfam read error
612 trace::err("cfam read 0x100b FAILED");
613 }
614 }
615}
616
Ben Tyneref320152020-01-09 10:31:23 -0600617} // namespace attn