blob: 3252078f8475830767ec8753b634cb7822603cca [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{
36
37/**
Ben Tyneref320152020-01-09 10:31:23 -060038 * @brief Handle checkstop attention
39 *
Ben Tynerb481d902020-03-05 10:24:23 -060040 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050041 * @return 0 indicates that the checkstop attention was successfully handled
42 * 1 indicates that the checkstop attention was NOT successfully
43 * handled.
Ben Tyneref320152020-01-09 10:31:23 -060044 */
Ben Tynerb481d902020-03-05 10:24:23 -060045int handleCheckstop(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060046
47/**
48 * @brief Handle special attention
49 *
Ben Tynerb481d902020-03-05 10:24:23 -060050 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050051 * @return 0 indicates that the special attention was successfully handled
52 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -060053 */
Ben Tynerb481d902020-03-05 10:24:23 -060054int handleSpecial(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060055
Ben Tynerfb190542020-11-06 09:27:56 -060056/** @brief Determine if attention is active and not masked */
Ben Tyner1965e502020-11-20 10:32:24 -060057bool activeAttn(uint32_t i_val, uint32_t i_mask, uint32_t i_attn);
Ben Tynerfb190542020-11-06 09:27:56 -060058
Ben Tynerb9715172021-09-29 08:46:19 -050059#ifdef CONFIG_PHAL_API
60/** @brief Handle phal sbe exception */
61void phalSbeExceptionHandler(openpower::phal::exception::SbeError& e,
Ben Tyner76e52f62022-02-01 10:46:44 -060062 uint32_t chipPosition, uint32_t command);
Ben Tynerb9715172021-09-29 08:46:19 -050063#endif
64
65/** @brief Get static TI info data based on host state */
66void getStaticTiInfo(uint8_t*& tiInfoPtr);
67
68/** @brief Check if TI info data is valid */
69bool tiInfoValid(uint8_t* tiInfo);
70
Ben Tyner6a69e6e2022-04-05 23:18:29 -050071/** @brief Clear attention interrupts */
72void clearAttnInterrupts();
73
Ben Tyneref320152020-01-09 10:31:23 -060074/**
Ben Tyneref320152020-01-09 10:31:23 -060075 * @brief The main attention handler logic
Ben Tyner970fd4f2020-02-19 13:46:42 -060076 *
77 * @param i_breakpoints true = breakpoint special attn handling enabled
Ben Tyneref320152020-01-09 10:31:23 -060078 */
Ben Tyner3fb52e52020-03-31 10:10:07 -050079void attnHandler(Config* i_config)
Ben Tyneref320152020-01-09 10:31:23 -060080{
austinfcuid28d5f82022-04-28 16:20:39 -050081 // Check if enClrAttnIntr is enabled
82 if (true == i_config->getFlag(enClrAttnIntr))
83 {
84 // Clear attention interrupts that may still be active (MPIPL)
85 clearAttnInterrupts();
86 }
Ben Tyner6a69e6e2022-04-05 23:18:29 -050087
Ben Tynerb481d902020-03-05 10:24:23 -060088 // Vector of active attentions to be handled
89 std::vector<Attention> active_attentions;
90
Ben Tyneref320152020-01-09 10:31:23 -060091 uint32_t isr_val, isr_mask;
Ben Tyneref320152020-01-09 10:31:23 -060092
93 // loop through processors looking for active attentions
austinfcuibfa831a2022-01-26 15:37:07 -060094 trace::inf("Attention handler started");
Ben Tyner117af992020-05-22 13:32:11 -050095
Ben Tyneref320152020-01-09 10:31:23 -060096 pdbg_target* target;
Ben Tyner5e622d82020-09-11 10:10:24 -050097 pdbg_for_each_class_target("proc", target)
Ben Tyneref320152020-01-09 10:31:23 -060098 {
99 if (PDBG_TARGET_ENABLED == pdbg_target_probe(target))
100 {
Zane Shelleya79f6c82021-01-12 16:38:49 -0600101 auto proc = pdbg_target_index(target); // get processor number
Ben Tyneref320152020-01-09 10:31:23 -0600102
Ben Tynerb83c8522020-11-20 10:45:26 -0600103 // Use PIB target to determine if a processor is enabled
Ben Tyner5e622d82020-09-11 10:10:24 -0500104 char path[16];
Ben Tynerb83c8522020-11-20 10:45:26 -0600105 sprintf(path, "/proc%d/pib", proc);
Ben Tyner8882c322021-02-05 12:13:21 -0600106 pdbg_target* pibTarget = pdbg_target_from_path(nullptr, path);
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500107
Ben Tynerb83c8522020-11-20 10:45:26 -0600108 // sanity check
Ben Tyner8882c322021-02-05 12:13:21 -0600109 if (nullptr == pibTarget)
Ben Tynerb83c8522020-11-20 10:45:26 -0600110 {
austinfcuibfa831a2022-01-26 15:37:07 -0600111 trace::inf("pib path or target not found");
Ben Tynerb83c8522020-11-20 10:45:26 -0600112 continue;
113 }
114
Ben Tyner8882c322021-02-05 12:13:21 -0600115 // check if pib target is enabled
116 if (PDBG_TARGET_ENABLED == pdbg_target_probe(pibTarget))
Ben Tyneref320152020-01-09 10:31:23 -0600117 {
Ben Tynerb83c8522020-11-20 10:45:26 -0600118 // The processor FSI target is required for CFAM read
119 sprintf(path, "/proc%d/fsi", proc);
Ben Tyner8882c322021-02-05 12:13:21 -0600120 pdbg_target* fsiTarget = pdbg_target_from_path(nullptr, path);
Ben Tynerb83c8522020-11-20 10:45:26 -0600121
122 // sanity check
Ben Tyner8882c322021-02-05 12:13:21 -0600123 if (nullptr == fsiTarget)
Ben Tynerb83c8522020-11-20 10:45:26 -0600124 {
austinfcuibfa831a2022-01-26 15:37:07 -0600125 trace::inf("fsi path or target not found");
Ben Tynerb83c8522020-11-20 10:45:26 -0600126 continue;
127 }
128
Ben Tyner8882c322021-02-05 12:13:21 -0600129 // trace the proc number
austinfcuibfa831a2022-01-26 15:37:07 -0600130 trace::inf("proc: %u", proc);
Ben Tyner1965e502020-11-20 10:32:24 -0600131
Ben Tyner5adc96e2020-11-20 10:54:12 -0600132 isr_val = 0xffffffff; // invalid isr value
133
Ben Tyner5e622d82020-09-11 10:10:24 -0500134 // get active attentions on processor
Ben Tyner8882c322021-02-05 12:13:21 -0600135 if (RC_SUCCESS != fsi_read(fsiTarget, 0x1007, &isr_val))
Ben Tyneref320152020-01-09 10:31:23 -0600136 {
Ben Tynerfb190542020-11-06 09:27:56 -0600137 // log cfam read error
austinfcuibfa831a2022-01-26 15:37:07 -0600138 trace::err("cfam read 0x1007 FAILED");
Ben Tyner7a0dd542021-02-12 09:33:44 -0600139 eventAttentionFail((int)AttnSection::attnHandler |
140 ATTN_PDBG_CFAM);
Ben Tyneref320152020-01-09 10:31:23 -0600141 }
Ben Tyner5adc96e2020-11-20 10:54:12 -0600142 else if (0xffffffff == isr_val)
143 {
austinfcuibfa831a2022-01-26 15:37:07 -0600144 trace::err("cfam read 0x1007 INVALID");
Ben Tyner5adc96e2020-11-20 10:54:12 -0600145 continue;
146 }
Ben Tyneref320152020-01-09 10:31:23 -0600147 else
148 {
Ben Tyner8882c322021-02-05 12:13:21 -0600149 // trace isr value
austinfcuibfa831a2022-01-26 15:37:07 -0600150 trace::inf("cfam 0x1007 = 0x%08x", isr_val);
Ben Tyner1965e502020-11-20 10:32:24 -0600151
Ben Tyner5adc96e2020-11-20 10:54:12 -0600152 isr_mask = 0xffffffff; // invalid isr mask
153
Ben Tyner5e622d82020-09-11 10:10:24 -0500154 // get interrupt enabled special attentions mask
Ben Tyner8882c322021-02-05 12:13:21 -0600155 if (RC_SUCCESS != fsi_read(fsiTarget, 0x100d, &isr_mask))
Ben Tyneref320152020-01-09 10:31:23 -0600156 {
Ben Tynerfb190542020-11-06 09:27:56 -0600157 // log cfam read error
austinfcuibfa831a2022-01-26 15:37:07 -0600158 trace::err("cfam read 0x100d FAILED");
Ben Tyner7a0dd542021-02-12 09:33:44 -0600159 eventAttentionFail((int)AttnSection::attnHandler |
160 ATTN_PDBG_CFAM);
Ben Tyneref320152020-01-09 10:31:23 -0600161 }
Ben Tyner5adc96e2020-11-20 10:54:12 -0600162 else if (0xffffffff == isr_mask)
163 {
austinfcuibfa831a2022-01-26 15:37:07 -0600164 trace::err("cfam read 0x100d INVALID");
Ben Tyner5adc96e2020-11-20 10:54:12 -0600165 continue;
166 }
Ben Tyner5e622d82020-09-11 10:10:24 -0500167 else
168 {
Ben Tyner8882c322021-02-05 12:13:21 -0600169 // trace true mask
austinfcuibfa831a2022-01-26 15:37:07 -0600170 trace::inf("cfam 0x100d = 0x%08x", isr_mask);
Ben Tyner1965e502020-11-20 10:32:24 -0600171
Ben Tynerfb190542020-11-06 09:27:56 -0600172 // SBE vital attention active and not masked?
Ben Tyner1965e502020-11-20 10:32:24 -0600173 if (true == activeAttn(isr_val, isr_mask, SBE_ATTN))
Ben Tyner5e622d82020-09-11 10:10:24 -0500174 {
175 active_attentions.emplace_back(Attention::Vital,
176 handleVital, target,
177 i_config);
178 }
179
Ben Tynerfb190542020-11-06 09:27:56 -0600180 // Checkstop attention active and not masked?
181 if (true ==
Ben Tyner1965e502020-11-20 10:32:24 -0600182 activeAttn(isr_val, isr_mask, CHECKSTOP_ATTN))
Ben Tyner5e622d82020-09-11 10:10:24 -0500183 {
184 active_attentions.emplace_back(Attention::Checkstop,
185 handleCheckstop,
186 target, i_config);
187 }
188
Ben Tynerfb190542020-11-06 09:27:56 -0600189 // Special attention active and not masked?
Ben Tyner1965e502020-11-20 10:32:24 -0600190 if (true == activeAttn(isr_val, isr_mask, SPECIAL_ATTN))
Ben Tyner5e622d82020-09-11 10:10:24 -0500191 {
192 active_attentions.emplace_back(Attention::Special,
193 handleSpecial,
194 target, i_config);
195 }
196 } // cfam 0x100d valid
197 } // cfam 0x1007 valid
Ben Tyner8882c322021-02-05 12:13:21 -0600198 } // fsi target enabled
199 } // pib target enabled
Ben Tyner5e622d82020-09-11 10:10:24 -0500200 } // next processor
Ben Tyneref320152020-01-09 10:31:23 -0600201
Ben Tynerb481d902020-03-05 10:24:23 -0600202 // convert to heap, highest priority is at front
203 if (!std::is_heap(active_attentions.begin(), active_attentions.end()))
204 {
205 std::make_heap(active_attentions.begin(), active_attentions.end());
206 }
207
208 // call the attention handler until one is handled or all were attempted
209 while (false == active_attentions.empty())
210 {
211 // handle highest priority attention, done if successful
212 if (RC_SUCCESS == active_attentions.front().handle())
213 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500214 // an attention was handled so we are done
Ben Tynerb481d902020-03-05 10:24:23 -0600215 break;
216 }
217
218 // move attention to back of vector
219 std::pop_heap(active_attentions.begin(), active_attentions.end());
220
221 // remove attention from vector
222 active_attentions.pop_back();
223 }
Ben Tyneref320152020-01-09 10:31:23 -0600224}
225
226/**
Ben Tyneref320152020-01-09 10:31:23 -0600227 * @brief Handle checkstop attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500228 *
229 * @param i_attention Attention object
230 * @return 0 indicates that the checkstop attention was successfully handled
231 * 1 indicates that the checkstop attention was NOT successfully
232 * handled.
Ben Tyneref320152020-01-09 10:31:23 -0600233 */
Ben Tynerb481d902020-03-05 10:24:23 -0600234int handleCheckstop(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600235{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500236 int rc = RC_SUCCESS; // assume checkstop handled
Ben Tyneref320152020-01-09 10:31:23 -0600237
austinfcuibfa831a2022-01-26 15:37:07 -0600238 trace::inf("checkstop handler started");
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500239
Ben Tynerb8335562021-07-16 12:43:52 -0500240 // capture some additional data for logs/traces
241 addHbStatusRegs();
242
Ben Tyner3fb52e52020-03-31 10:10:07 -0500243 // if checkstop handling enabled, handle checkstop attention
244 if (false == (i_attention->getConfig()->getFlag(enCheckstop)))
245 {
austinfcuibfa831a2022-01-26 15:37:07 -0600246 trace::inf("Checkstop handling disabled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500247 }
248 else
249 {
Ben Tyner07ebb9b2021-12-01 12:16:24 -0600250 // wait for power fault handling before starting analyses
251 sleepSeconds(POWER_FAULT_WAIT);
252
Zane Shelley9fb73932020-09-15 13:34:57 -0500253 // Look for any attentions found in hardware. This will generate and
Zane Shelley7ae9c8c2020-12-02 20:10:31 -0600254 // commit a PEL if any errors are found.
Ben Tyner7029e522021-08-09 19:18:24 -0500255 DumpParameters dumpParameters;
Zane Shelleyebff0d32021-11-21 10:52:07 -0600256 auto logid = analyzer::analyzeHardware(
257 analyzer::AnalysisType::SYSTEM_CHECKSTOP, dumpParameters);
Zane Shelley611b3442021-11-19 16:02:01 -0600258 if (0 == logid)
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500259 {
Zane Shelley611b3442021-11-19 16:02:01 -0600260 // A PEL should exist for a checkstop attention.
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500261 rc = RC_ANALYZER_ERROR;
262 }
Ben Tyner7029e522021-08-09 19:18:24 -0500263 else
264 {
Zane Shelley611b3442021-11-19 16:02:01 -0600265 requestDump(logid, dumpParameters);
Ben Tyner7029e522021-08-09 19:18:24 -0500266 util::dbus::transitionHost(util::dbus::HostState::Quiesce);
267 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500268 }
Ben Tyneref320152020-01-09 10:31:23 -0600269
Ben Tyneref320152020-01-09 10:31:23 -0600270 return rc;
271}
272
273/**
274 * @brief Handle special attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500275 *
276 * @param i_attention Attention object
277 * @return 0 indicates that the special attention was successfully handled
278 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600279 */
Ben Tynerb481d902020-03-05 10:24:23 -0600280int handleSpecial(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600281{
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500282 int rc = RC_SUCCESS; // assume special attention handled
Ben Tyneref320152020-01-09 10:31:23 -0600283
Ben Tynerfb190542020-11-06 09:27:56 -0600284 // The TI info chipop will give us a pointer to the TI info data
Ben Tyner98430b32020-08-19 19:14:02 -0500285 uint8_t* tiInfo = nullptr; // ptr to TI info data
286 uint32_t tiInfoLen = 0; // length of TI info data
287 pdbg_target* attnProc = i_attention->getTarget(); // proc with attention
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500288
Ben Tyner29651ef2021-02-08 10:51:03 -0600289 bool tiInfoStatic = false; // assume TI info was provided (not created)
290
Ben Tynerb9715172021-09-29 08:46:19 -0500291 // need proc target to get dynamic TI info
292 if (nullptr != attnProc)
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500293 {
Ben Tynerb9715172021-09-29 08:46:19 -0500294#ifdef CONFIG_PHAL_API
austinfcuibfa831a2022-01-26 15:37:07 -0600295 trace::inf("using libphal to get TI info");
Ben Tynerb9715172021-09-29 08:46:19 -0500296
297 // phal library uses proc target for get ti info
298 if (PDBG_TARGET_ENABLED == pdbg_target_probe(attnProc))
299 {
300 try
301 {
302 // get dynamic TI info
303 openpower::phal::sbe::getTiInfo(attnProc, &tiInfo, &tiInfoLen);
304 }
Ben Tyner76e52f62022-02-01 10:46:44 -0600305 catch (openpower::phal::exception::SbeError& sbeError)
Ben Tynerb9715172021-09-29 08:46:19 -0500306 {
307 // library threw an exception
Ben Tyner76e52f62022-02-01 10:46:44 -0600308 // note: phal::sbe::getTiInfo = command class | command ==
309 // 0xa900 | 0x04 = 0xa904. The sbe fifo command class and
Ben Tyner6a69e6e2022-04-05 23:18:29 -0500310 // commands are defined in the sbefifo library source code
311 // but do not seem to be exported/installed for consumption
Ben Tyner76e52f62022-02-01 10:46:44 -0600312 // externally.
Ben Tynerb9715172021-09-29 08:46:19 -0500313 uint32_t procNum = pdbg_target_index(attnProc);
Ben Tyner76e52f62022-02-01 10:46:44 -0600314 phalSbeExceptionHandler(sbeError, procNum, 0xa904);
Ben Tynerb9715172021-09-29 08:46:19 -0500315 }
316 }
317#else
austinfcuibfa831a2022-01-26 15:37:07 -0600318 trace::inf("using libpdbg to get TI info");
Ben Tynerb9715172021-09-29 08:46:19 -0500319
320 // pdbg library uses pib target for get ti info
Ben Tyner98430b32020-08-19 19:14:02 -0500321 char path[16];
322 sprintf(path, "/proc%d/pib", pdbg_target_index(attnProc));
323 pdbg_target* tiInfoTarget = pdbg_target_from_path(nullptr, path);
324
325 if (nullptr != tiInfoTarget)
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500326 {
Ben Tyner98430b32020-08-19 19:14:02 -0500327 if (PDBG_TARGET_ENABLED == pdbg_target_probe(tiInfoTarget))
328 {
Ben Tyner98430b32020-08-19 19:14:02 -0500329 sbe_mpipl_get_ti_info(tiInfoTarget, &tiInfo, &tiInfoLen);
Ben Tyner98430b32020-08-19 19:14:02 -0500330 }
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500331 }
Ben Tynerb9715172021-09-29 08:46:19 -0500332#endif
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500333 }
Ben Tyneref320152020-01-09 10:31:23 -0600334
Ben Tynerb9715172021-09-29 08:46:19 -0500335 // dynamic TI info is not available
336 if (nullptr == tiInfo)
Ben Tyner970fd4f2020-02-19 13:46:42 -0600337 {
austinfcuibfa831a2022-01-26 15:37:07 -0600338 trace::inf("TI info data ptr is invalid");
Ben Tynerb9715172021-09-29 08:46:19 -0500339 getStaticTiInfo(tiInfo);
340 tiInfoStatic = true;
Ben Tyner3fb52e52020-03-31 10:10:07 -0500341 }
Ben Tyner0fe5df42020-12-03 08:57:17 -0600342
Ben Tynerb9715172021-09-29 08:46:19 -0500343 // check TI info for validity and handle
344 if (true == tiInfoValid(tiInfo))
345 {
346 // TI info is valid handle TI if support enabled
347 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
348 {
349 // Call TI special attention handler
350 rc = tiHandler((TiDataArea*)tiInfo);
351 }
352 }
353 else
Ben Tyner3fb52e52020-03-31 10:10:07 -0500354 {
austinfcuibfa831a2022-01-26 15:37:07 -0600355 trace::inf("TI info NOT valid");
Ben Tyner98430b32020-08-19 19:14:02 -0500356
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500357 // if configured to handle TI as default special attention
Ben Tynerfe156492021-04-08 07:28:13 -0500358 if (i_attention->getConfig()->getFlag(dfltTi))
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500359 {
Ben Tynerfe156492021-04-08 07:28:13 -0500360 // TI handling may be disabled
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500361 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
362 {
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500363 // Call TI special attention handler
Ben Tynerb9715172021-09-29 08:46:19 -0500364 rc = tiHandler((TiDataArea*)tiInfo);
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500365 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500366 }
Ben Tynerb9715172021-09-29 08:46:19 -0500367 // configured to handle breakpoint as default special attention
Ben Tynerfe156492021-04-08 07:28:13 -0500368 else
369 {
370 // breakpoint handling may be disabled
371 if (true == (i_attention->getConfig()->getFlag(enBreakpoints)))
372 {
373 // Call the breakpoint special attention handler
374 rc = bpHandler();
375 }
376 }
Ben Tyner970fd4f2020-02-19 13:46:42 -0600377 }
Ben Tyneref320152020-01-09 10:31:23 -0600378
Ben Tynerb9715172021-09-29 08:46:19 -0500379 // release TI data buffer if not ours
380 if (false == tiInfoStatic)
Ben Tyner792f32f2020-06-02 08:50:47 -0500381 {
Ben Tynerb9715172021-09-29 08:46:19 -0500382 // sanity check
383 if (nullptr != tiInfo)
384 {
385 free(tiInfo);
386 }
Ben Tyner792f32f2020-06-02 08:50:47 -0500387 }
388
Ben Tynerb9715172021-09-29 08:46:19 -0500389 // trace non-successful exit condition
Ben Tyner3fb52e52020-03-31 10:10:07 -0500390 if (RC_SUCCESS != rc)
391 {
austinfcuibfa831a2022-01-26 15:37:07 -0600392 trace::inf("Special attn not handled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500393 }
Ben Tyneref320152020-01-09 10:31:23 -0600394
395 return rc;
396}
397
Ben Tynerfb190542020-11-06 09:27:56 -0600398/**
399 * @brief Determine if attention is active and not masked
400 *
401 * Determine whether an attention needs to be handled and trace details of
402 * attention type and whether it is masked or not.
403 *
404 * @param i_val attention status register
405 * @param i_mask attention true mask register
406 * @param i_attn attention type
407 * @param i_proc processor associated with registers
408 *
409 * @return true if attention is active and not masked, otherwise false
410 */
Ben Tyner1965e502020-11-20 10:32:24 -0600411bool activeAttn(uint32_t i_val, uint32_t i_mask, uint32_t i_attn)
Ben Tynerfb190542020-11-06 09:27:56 -0600412{
Zane Shelley9fb657f2021-01-12 15:30:58 -0600413 bool rc = false; // assume attn masked and/or inactive
Ben Tynerfb190542020-11-06 09:27:56 -0600414
415 // if attention active
416 if (0 != (i_val & i_attn))
417 {
austinfcuibfa831a2022-01-26 15:37:07 -0600418 std::string msg;
Ben Tynerfb190542020-11-06 09:27:56 -0600419
Zane Shelley9fb657f2021-01-12 15:30:58 -0600420 bool validAttn = true; // known attention type
421
Ben Tynerfb190542020-11-06 09:27:56 -0600422 switch (i_attn)
423 {
424 case SBE_ATTN:
austinfcuibfa831a2022-01-26 15:37:07 -0600425 msg = "SBE attn";
Ben Tynerfb190542020-11-06 09:27:56 -0600426 break;
427 case CHECKSTOP_ATTN:
austinfcuibfa831a2022-01-26 15:37:07 -0600428 msg = "Checkstop attn";
Ben Tynerfb190542020-11-06 09:27:56 -0600429 break;
430 case SPECIAL_ATTN:
austinfcuibfa831a2022-01-26 15:37:07 -0600431 msg = "Special attn";
Ben Tynerfb190542020-11-06 09:27:56 -0600432 break;
433 default:
austinfcuibfa831a2022-01-26 15:37:07 -0600434 msg = "Unknown attn";
Ben Tynerfb190542020-11-06 09:27:56 -0600435 validAttn = false;
436 }
437
438 // see if attention is masked
439 if (true == validAttn)
440 {
441 if (0 != (i_mask & i_attn))
442 {
443 rc = true; // attention active and not masked
444 }
445 else
446 {
austinfcuibfa831a2022-01-26 15:37:07 -0600447 msg += " masked";
Ben Tynerfb190542020-11-06 09:27:56 -0600448 }
449 }
450
austinfcuibfa831a2022-01-26 15:37:07 -0600451 trace::inf(msg.c_str()); // commit trace stream
Ben Tynerfb190542020-11-06 09:27:56 -0600452 }
453
454 return rc;
455}
Ben Tynerb9715172021-09-29 08:46:19 -0500456
457#ifdef CONFIG_PHAL_API
Ben Tyner76e52f62022-02-01 10:46:44 -0600458
Ben Tynerb9715172021-09-29 08:46:19 -0500459/**
460 * @brief Handle phal sbe exception
461 *
462 * @param[in] e - exception object
463 * @param[in] procNum - processor number associated with sbe exception
464 */
Ben Tyner76e52f62022-02-01 10:46:44 -0600465void phalSbeExceptionHandler(openpower::phal::exception::SbeError& sbeError,
466 uint32_t chipPosition, uint32_t command)
Ben Tynerb9715172021-09-29 08:46:19 -0500467{
Ben Tyner76e52f62022-02-01 10:46:44 -0600468 trace::err("Attention handler phal exception handler");
Ben Tynerb9715172021-09-29 08:46:19 -0500469
Ben Tyner76e52f62022-02-01 10:46:44 -0600470 // Trace exception details
471 trace::err(sbeError.what());
472
473 // Create event log entry with SBE FFDC data if provided
474 auto fd = sbeError.getFd();
475 if (fd > 0)
Ben Tynerb9715172021-09-29 08:46:19 -0500476 {
Ben Tyner76e52f62022-02-01 10:46:44 -0600477 trace::err("SBE FFDC data is available");
478
479 // FFDC parser expects chip position and command (command class |
480 // command) to be in the additional data.
481 std::map<std::string, std::string> additionalData = {
482 {"SRC6", std::to_string((chipPosition << 16) | command)}};
483
Ben Tyner6a69e6e2022-04-05 23:18:29 -0500484 // See phosphor-logging/extensions/openpower-pels/README.md, "Self
485 // Boot Engine(SBE) First Failure Data Capture(FFDC)" - SBE FFDC
486 // file type is 0xCB, version is 0x01.
Ben Tyner76e52f62022-02-01 10:46:44 -0600487 std::vector<util::FFDCTuple> ffdc{util::FFDCTuple{
488 util::FFDCFormat::Custom, static_cast<uint8_t>(0xCB),
489 static_cast<uint8_t>(0x01), fd}};
490
491 // Create event log entry with FFDC data
Ben Tyner13159682022-02-16 14:55:38 -0600492 util::dbus::createPel("org.open_power.Processor.Error.SbeChipOpFailure",
493 levelPelError, additionalData, ffdc);
Ben Tynerb9715172021-09-29 08:46:19 -0500494 }
495}
496#endif
497
498/**
499 * @brief Get static TI info data based on host state
500 *
501 * @param[out] tiInfo - pointer to static TI info data
502 */
503void getStaticTiInfo(uint8_t*& tiInfo)
504{
505 util::dbus::HostRunningState runningState = util::dbus::hostRunningState();
506
507 // assume host state is unknown
508 std::string stateString = "host state unknown";
509
510 if ((util::dbus::HostRunningState::Started == runningState) ||
511 (util::dbus::HostRunningState::Unknown == runningState))
512 {
513 if (util::dbus::HostRunningState::Started == runningState)
514 {
515 stateString = "host started";
516 }
517 tiInfo = (uint8_t*)defaultPhypTiInfo;
518 }
519 else
520 {
521 stateString = "host not started";
522 tiInfo = (uint8_t*)defaultHbTiInfo;
523 }
524
525 // trace host state
austinfcuibfa831a2022-01-26 15:37:07 -0600526 trace::inf(stateString.c_str());
Ben Tynerb9715172021-09-29 08:46:19 -0500527}
528
529/**
530 * @brief Check if TI info data is valid
531 *
532 * @param[in] tiInfo - pointer to TI info data
533 * @return true if TI info data is valid, else false
534 */
535bool tiInfoValid(uint8_t* tiInfo)
536{
537 bool tiInfoValid = false; // assume TI info invalid
538
539 // TI info data[0] non-zero indicates TI info valid (usually)
540 if ((nullptr != tiInfo) && (0 != tiInfo[0]))
541 {
542 TiDataArea* tiDataArea = (TiDataArea*)tiInfo;
543
Ben Tynerb9715172021-09-29 08:46:19 -0500544 // trace a few known TI data area values
Ben Tyner535a8d42022-03-08 18:07:14 -0600545 trace::inf("TI data command = 0x%02x", tiDataArea->command);
Ben Tynerb9715172021-09-29 08:46:19 -0500546
547 // Another check for valid TI Info since it has been seen that
548 // tiInfo[0] != 0 but TI info is not valid
549 if (0xa1 == tiDataArea->command)
550 {
551 tiInfoValid = true;
552
553 // trace some more data since TI info appears valid
Ben Tyner535a8d42022-03-08 18:07:14 -0600554 trace::inf("TI data term-type = 0x%02x",
austinfcuibfa831a2022-01-26 15:37:07 -0600555 tiDataArea->hbTerminateType);
Ben Tynerb9715172021-09-29 08:46:19 -0500556
Ben Tyner535a8d42022-03-08 18:07:14 -0600557 trace::inf("TI data SRC format = 0x%02x", tiDataArea->srcFormat);
Ben Tynerb9715172021-09-29 08:46:19 -0500558
Ben Tyner535a8d42022-03-08 18:07:14 -0600559 trace::inf("TI data source = 0x%02x", tiDataArea->source);
Ben Tynerb9715172021-09-29 08:46:19 -0500560 }
561 }
562
563 return tiInfoValid;
564}
565
Ben Tyner6a69e6e2022-04-05 23:18:29 -0500566/**
567 * @brief Clear attention interrupts
568 *
569 * The attention interrupts are sticky and may still be set (MPIPL) even if
570 * there are no active attentions. If there is an active attention then
571 * clearing the associated interrupt will have no effect.
572 */
573void clearAttnInterrupts()
574{
575 trace::inf("Clearing attention interrupts");
576
577 // loop through processors clearing attention interrupts
578 pdbg_target* procTarget;
579 pdbg_for_each_class_target("proc", procTarget)
580 {
581 // active processors only
582 if (PDBG_TARGET_ENABLED !=
583 pdbg_target_probe(util::pdbg::getPibTrgt(procTarget)))
584 {
585 continue;
586 }
587
588 // get cfam is an fsi read
589 pdbg_target* fsiTarget = util::pdbg::getFsiTrgt(procTarget);
590 uint32_t int_val;
591
592 // get attention interrupts on processor
593 if (RC_SUCCESS == fsi_read(fsiTarget, 0x100b, &int_val))
594 {
595 // trace int value
596 trace::inf("cfam 0x100b = 0x%08x", int_val);
597
598 int_val &= ~(ANY_ATTN | CHECKSTOP_ATTN | SPECIAL_ATTN |
599 RECOVERABLE_ATTN | SBE_ATTN);
600
601 // clear attention interrupts on processor
602 if (RC_SUCCESS != fsi_write(fsiTarget, 0x100b, int_val))
603 {
604 // log cfam write error
605 trace::err("cfam write 0x100b FAILED");
606 }
607 }
608 else
609 {
610 // log cfam read error
611 trace::err("cfam read 0x100b FAILED");
612 }
613 }
614}
615
Ben Tyneref320152020-01-09 10:31:23 -0600616} // namespace attn