blob: 3e51f5708be31992dceaaeeae81e11cd5f4ff38c [file] [log] [blame]
Ben Tyner792f32f2020-06-02 08:50:47 -05001#include <libpdbg.h>
2
Ben Tyner0205f3b2020-02-24 10:24:47 -06003#include <analyzer/analyzer_main.hpp>
Ben Tynerb797b3e2020-06-29 10:12:05 -05004#include <attn/attention.hpp>
5#include <attn/attn_config.hpp>
6#include <attn/attn_handler.hpp>
7#include <attn/attn_logging.hpp>
8#include <attn/bp_handler.hpp>
9#include <attn/ti_handler.hpp>
Ben Tyneref320152020-01-09 10:31:23 -060010
Ben Tynerb481d902020-03-05 10:24:23 -060011#include <algorithm>
Ben Tyneref320152020-01-09 10:31:23 -060012#include <iomanip>
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050013#include <map>
Ben Tyner9ae5ca42020-02-28 13:13:50 -060014#include <sstream>
Ben Tynerb481d902020-03-05 10:24:23 -060015#include <vector>
Ben Tyneref320152020-01-09 10:31:23 -060016
17namespace attn
18{
19
20/**
21 * @brief Handle SBE vital attention
22 *
Ben Tynerb481d902020-03-05 10:24:23 -060023 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050024 * @return 0 indicates that the vital attention was successfully handled
25 * 1 indicates that the vital attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -060026 */
Ben Tynerb481d902020-03-05 10:24:23 -060027int handleVital(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060028
29/**
30 * @brief Handle checkstop attention
31 *
Ben Tynerb481d902020-03-05 10:24:23 -060032 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050033 * @return 0 indicates that the checkstop attention was successfully handled
34 * 1 indicates that the checkstop attention was NOT successfully
35 * handled.
Ben Tyneref320152020-01-09 10:31:23 -060036 */
Ben Tynerb481d902020-03-05 10:24:23 -060037int handleCheckstop(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060038
39/**
40 * @brief Handle special attention
41 *
Ben Tynerb481d902020-03-05 10:24:23 -060042 * @param i_attention Attention object
Ben Tyner3fb52e52020-03-31 10:10:07 -050043 * @return 0 indicates that the special attention was successfully handled
44 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -060045 */
Ben Tynerb481d902020-03-05 10:24:23 -060046int handleSpecial(Attention* i_attention);
Ben Tyneref320152020-01-09 10:31:23 -060047
Ben Tynerfb190542020-11-06 09:27:56 -060048/** @brief Determine if attention is active and not masked */
Ben Tyner1965e502020-11-20 10:32:24 -060049bool activeAttn(uint32_t i_val, uint32_t i_mask, uint32_t i_attn);
Ben Tynerfb190542020-11-06 09:27:56 -060050
Ben Tyneref320152020-01-09 10:31:23 -060051/**
Ben Tyneref320152020-01-09 10:31:23 -060052 * @brief The main attention handler logic
Ben Tyner970fd4f2020-02-19 13:46:42 -060053 *
54 * @param i_breakpoints true = breakpoint special attn handling enabled
Ben Tyneref320152020-01-09 10:31:23 -060055 */
Ben Tyner3fb52e52020-03-31 10:10:07 -050056void attnHandler(Config* i_config)
Ben Tyneref320152020-01-09 10:31:23 -060057{
Ben Tynerb481d902020-03-05 10:24:23 -060058 // Vector of active attentions to be handled
59 std::vector<Attention> active_attentions;
60
Ben Tyneref320152020-01-09 10:31:23 -060061 uint32_t isr_val, isr_mask;
62 uint32_t proc;
63
Ben Tyner1965e502020-11-20 10:32:24 -060064 std::stringstream ss; // for trace messages
65
Ben Tyneref320152020-01-09 10:31:23 -060066 // loop through processors looking for active attentions
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050067 trace<level::INFO>("Attention handler started");
Ben Tyner117af992020-05-22 13:32:11 -050068
Ben Tyneref320152020-01-09 10:31:23 -060069 pdbg_target* target;
Ben Tyner5e622d82020-09-11 10:10:24 -050070 pdbg_for_each_class_target("proc", target)
Ben Tyneref320152020-01-09 10:31:23 -060071 {
72 if (PDBG_TARGET_ENABLED == pdbg_target_probe(target))
73 {
74 proc = pdbg_target_index(target); // get processor number
75
Ben Tynerb83c8522020-11-20 10:45:26 -060076 // Use PIB target to determine if a processor is enabled
Ben Tyner5e622d82020-09-11 10:10:24 -050077 char path[16];
Ben Tynerb83c8522020-11-20 10:45:26 -060078 sprintf(path, "/proc%d/pib", proc);
Ben Tyner5e622d82020-09-11 10:10:24 -050079 pdbg_target* attnTarget = pdbg_target_from_path(nullptr, path);
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050080
Ben Tynerb83c8522020-11-20 10:45:26 -060081 // sanity check
82 if (nullptr == attnTarget)
83 {
84 trace<level::INFO>("pib path or target not found");
85 continue;
86 }
87
Ben Tyner5e622d82020-09-11 10:10:24 -050088 if (PDBG_TARGET_ENABLED == pdbg_target_probe(attnTarget))
Ben Tyneref320152020-01-09 10:31:23 -060089 {
Ben Tynerb83c8522020-11-20 10:45:26 -060090 // The processor FSI target is required for CFAM read
91 sprintf(path, "/proc%d/fsi", proc);
92 attnTarget = pdbg_target_from_path(nullptr, path);
93
94 // sanity check
95 if (nullptr == attnTarget)
96 {
97 trace<level::INFO>("fsi path or target not found");
98 continue;
99 }
100
Ben Tyner1965e502020-11-20 10:32:24 -0600101 // trace fsi path
102 ss.str(std::string()); // clear stream
103 ss << "target - " << path;
104 trace<level::INFO>(ss.str().c_str());
105
Ben Tyner5e622d82020-09-11 10:10:24 -0500106 // get active attentions on processor
107 if (RC_SUCCESS != fsi_read(attnTarget, 0x1007, &isr_val))
Ben Tyneref320152020-01-09 10:31:23 -0600108 {
Ben Tynerfb190542020-11-06 09:27:56 -0600109 // log cfam read error
Ben Tyner5e622d82020-09-11 10:10:24 -0500110 trace<level::INFO>("Error! cfam read 0x1007 FAILED");
Ben Tynerfb190542020-11-06 09:27:56 -0600111 eventAttentionFail(RC_CFAM_ERROR);
Ben Tyneref320152020-01-09 10:31:23 -0600112 }
113 else
114 {
Ben Tyner1965e502020-11-20 10:32:24 -0600115 // trace isr
116 ss.str(std::string()); // clear stream
117 ss << std::hex << std::showbase; // trace as hex vals
118 ss << "cfam 0x1007 = " << std::setw(8) << std::setfill('0')
119 << isr_val;
120 trace<level::INFO>(ss.str().c_str());
121
Ben Tyner5e622d82020-09-11 10:10:24 -0500122 // get interrupt enabled special attentions mask
123 if (RC_SUCCESS != fsi_read(attnTarget, 0x100d, &isr_mask))
Ben Tyneref320152020-01-09 10:31:23 -0600124 {
Ben Tynerfb190542020-11-06 09:27:56 -0600125 // log cfam read error
Ben Tyner5e622d82020-09-11 10:10:24 -0500126 trace<level::INFO>("Error! cfam read 0x100d FAILED");
Ben Tynerfb190542020-11-06 09:27:56 -0600127 eventAttentionFail(RC_CFAM_ERROR);
Ben Tyneref320152020-01-09 10:31:23 -0600128 }
Ben Tyner5e622d82020-09-11 10:10:24 -0500129 else
130 {
Ben Tyner1965e502020-11-20 10:32:24 -0600131 // trace true-mask
132 ss.str(std::string()); // clear stream
133 ss << std::hex << std::showbase; // trace as hex vals
134 ss << "cfam 0x100d = " << std::setw(8)
135 << std::setfill('0') << isr_mask;
136 trace<level::INFO>(ss.str().c_str());
137
Ben Tynerfb190542020-11-06 09:27:56 -0600138 // SBE vital attention active and not masked?
Ben Tyner1965e502020-11-20 10:32:24 -0600139 if (true == activeAttn(isr_val, isr_mask, SBE_ATTN))
Ben Tyner5e622d82020-09-11 10:10:24 -0500140 {
141 active_attentions.emplace_back(Attention::Vital,
142 handleVital, target,
143 i_config);
144 }
145
Ben Tynerfb190542020-11-06 09:27:56 -0600146 // Checkstop attention active and not masked?
147 if (true ==
Ben Tyner1965e502020-11-20 10:32:24 -0600148 activeAttn(isr_val, isr_mask, CHECKSTOP_ATTN))
Ben Tyner5e622d82020-09-11 10:10:24 -0500149 {
150 active_attentions.emplace_back(Attention::Checkstop,
151 handleCheckstop,
152 target, i_config);
153 }
154
Ben Tynerfb190542020-11-06 09:27:56 -0600155 // Special attention active and not masked?
Ben Tyner1965e502020-11-20 10:32:24 -0600156 if (true == activeAttn(isr_val, isr_mask, SPECIAL_ATTN))
Ben Tyner5e622d82020-09-11 10:10:24 -0500157 {
158 active_attentions.emplace_back(Attention::Special,
159 handleSpecial,
160 target, i_config);
161 }
162 } // cfam 0x100d valid
163 } // cfam 0x1007 valid
164 } // proc target enabled
165 } // fsi target enabled
166 } // next processor
Ben Tyneref320152020-01-09 10:31:23 -0600167
Ben Tynerb481d902020-03-05 10:24:23 -0600168 // convert to heap, highest priority is at front
169 if (!std::is_heap(active_attentions.begin(), active_attentions.end()))
170 {
171 std::make_heap(active_attentions.begin(), active_attentions.end());
172 }
173
174 // call the attention handler until one is handled or all were attempted
175 while (false == active_attentions.empty())
176 {
177 // handle highest priority attention, done if successful
178 if (RC_SUCCESS == active_attentions.front().handle())
179 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500180 // an attention was handled so we are done
Ben Tynerb481d902020-03-05 10:24:23 -0600181 break;
182 }
183
184 // move attention to back of vector
185 std::pop_heap(active_attentions.begin(), active_attentions.end());
186
187 // remove attention from vector
188 active_attentions.pop_back();
189 }
Ben Tyneref320152020-01-09 10:31:23 -0600190}
191
192/**
193 * @brief Handle SBE vital attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500194 *
195 * @param i_attention Attention object
196 * @return 0 indicates that the vital attention was successfully handled
197 * 1 indicates that the vital attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600198 */
Ben Tynerb481d902020-03-05 10:24:23 -0600199int handleVital(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600200{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500201 int rc = RC_SUCCESS; // assume vital handled
Ben Tyneref320152020-01-09 10:31:23 -0600202
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500203 trace<level::INFO>("vital handler started");
204
Ben Tyner3fb52e52020-03-31 10:10:07 -0500205 // if vital handling enabled, handle vital attention
206 if (false == (i_attention->getConfig()->getFlag(enVital)))
207 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500208 trace<level::INFO>("vital handling disabled");
Ben Tyner792f32f2020-06-02 08:50:47 -0500209 rc = RC_NOT_HANDLED;
Ben Tyner3fb52e52020-03-31 10:10:07 -0500210 }
211 else
Ben Tyneref320152020-01-09 10:31:23 -0600212 {
Ben Tyner792f32f2020-06-02 08:50:47 -0500213 eventVital();
Ben Tyneref320152020-01-09 10:31:23 -0600214 }
215
216 return rc;
217}
218
219/**
220 * @brief Handle checkstop attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500221 *
222 * @param i_attention Attention object
223 * @return 0 indicates that the checkstop attention was successfully handled
224 * 1 indicates that the checkstop attention was NOT successfully
225 * handled.
Ben Tyneref320152020-01-09 10:31:23 -0600226 */
Ben Tynerb481d902020-03-05 10:24:23 -0600227int handleCheckstop(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600228{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500229 int rc = RC_SUCCESS; // assume checkstop handled
Ben Tyneref320152020-01-09 10:31:23 -0600230
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500231 trace<level::INFO>("checkstop handler started");
232
Ben Tyner3fb52e52020-03-31 10:10:07 -0500233 // if checkstop handling enabled, handle checkstop attention
234 if (false == (i_attention->getConfig()->getFlag(enCheckstop)))
235 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500236 trace<level::INFO>("Checkstop handling disabled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500237 }
238 else
239 {
Zane Shelley9fb73932020-09-15 13:34:57 -0500240 // Look for any attentions found in hardware. This will generate and
Zane Shelley7ae9c8c2020-12-02 20:10:31 -0600241 // commit a PEL if any errors are found.
Zane Shelley9fb73932020-09-15 13:34:57 -0500242 if (true != analyzer::analyzeHardware())
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500243 {
244 rc = RC_ANALYZER_ERROR;
245 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500246 }
Ben Tyneref320152020-01-09 10:31:23 -0600247
Ben Tyneref320152020-01-09 10:31:23 -0600248 return rc;
249}
250
251/**
252 * @brief Handle special attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500253 *
254 * @param i_attention Attention object
255 * @return 0 indicates that the special attention was successfully handled
256 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600257 */
Ben Tynerb481d902020-03-05 10:24:23 -0600258int handleSpecial(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600259{
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500260 int rc = RC_SUCCESS; // assume special attention handled
Ben Tyneref320152020-01-09 10:31:23 -0600261
Ben Tynerfb190542020-11-06 09:27:56 -0600262 // The TI info chipop will give us a pointer to the TI info data
Ben Tyner98430b32020-08-19 19:14:02 -0500263 uint8_t* tiInfo = nullptr; // ptr to TI info data
264 uint32_t tiInfoLen = 0; // length of TI info data
265 pdbg_target* attnProc = i_attention->getTarget(); // proc with attention
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500266
Ben Tyner98430b32020-08-19 19:14:02 -0500267 if (attnProc != nullptr)
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500268 {
Ben Tyner98430b32020-08-19 19:14:02 -0500269 // The processor PIB target is required for get TI info chipop
270 char path[16];
271 sprintf(path, "/proc%d/pib", pdbg_target_index(attnProc));
272 pdbg_target* tiInfoTarget = pdbg_target_from_path(nullptr, path);
273
274 if (nullptr != tiInfoTarget)
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500275 {
Ben Tyner98430b32020-08-19 19:14:02 -0500276 if (PDBG_TARGET_ENABLED == pdbg_target_probe(tiInfoTarget))
277 {
Ben Tyner98430b32020-08-19 19:14:02 -0500278 sbe_mpipl_get_ti_info(tiInfoTarget, &tiInfo, &tiInfoLen);
279 if (tiInfo == nullptr)
280 {
281 trace<level::INFO>("TI info data ptr is null after call");
282 }
283 }
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500284 }
285 }
Ben Tyneref320152020-01-09 10:31:23 -0600286
Ben Tyner792f32f2020-06-02 08:50:47 -0500287 // If TI area exists and is marked valid we can assume TI occurred
288 if ((nullptr != tiInfo) && (0 != tiInfo[0]))
Ben Tyner970fd4f2020-02-19 13:46:42 -0600289 {
Ben Tyner792f32f2020-06-02 08:50:47 -0500290 TiDataArea* tiDataArea = (TiDataArea*)tiInfo;
Ben Tyner7e6611f2020-02-13 16:42:56 -0600291
Ben Tyner792f32f2020-06-02 08:50:47 -0500292 // trace a few known TI data area values
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500293 std::stringstream ss;
294 ss << std::hex << std::showbase;
Ben Tyner40717722020-09-23 09:43:20 -0500295
296 ss << "TI data command = " << (int)tiDataArea->command;
Ben Tyner792f32f2020-06-02 08:50:47 -0500297 trace<level::INFO>(ss.str().c_str());
Ben Tyner40717722020-09-23 09:43:20 -0500298 ss.str(std::string());
299
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500300 ss << "TI data hb_terminate_type = "
301 << (int)tiDataArea->hbTerminateType;
302 trace<level::INFO>(ss.str().c_str());
303 ss.str(std::string());
304
Ben Tyner40717722020-09-23 09:43:20 -0500305 ss << "TI data SRC format = " << (int)tiDataArea->srcFormat;
Ben Tyner792f32f2020-06-02 08:50:47 -0500306 trace<level::INFO>(ss.str().c_str());
Ben Tyner40717722020-09-23 09:43:20 -0500307 ss.str(std::string());
308
Ben Tyner8c5e4f42020-10-28 11:11:55 -0500309 ss << "TI data source = " << (int)tiDataArea->source;
Ben Tyner792f32f2020-06-02 08:50:47 -0500310 trace<level::INFO>(ss.str().c_str());
Ben Tyner40717722020-09-23 09:43:20 -0500311 ss.str(std::string());
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500312
Ben Tyner792f32f2020-06-02 08:50:47 -0500313 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
314 {
Ben Tyner792f32f2020-06-02 08:50:47 -0500315 // Call TI special attention handler
316 rc = tiHandler(tiDataArea);
317 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500318 }
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500319 // TI area not valid or not available
Ben Tyner3fb52e52020-03-31 10:10:07 -0500320 else
321 {
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500322 trace<level::INFO>("TI info NOT available");
Ben Tyner98430b32020-08-19 19:14:02 -0500323
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500324 // if configured to handle breakpoint as default special attention
325 if (i_attention->getConfig()->getFlag(dfltBreakpoint))
Ben Tyner3fb52e52020-03-31 10:10:07 -0500326 {
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500327 if (true == (i_attention->getConfig()->getFlag(enBreakpoints)))
328 {
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500329 // Call the breakpoint special attention handler
330 bpHandler();
331 }
332 }
333 // if configured to handle TI as default special attention
334 else
335 {
336 trace<level::INFO>("assuming TI");
337
338 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
339 {
Ben Tynere4f5dbe2020-10-19 07:19:33 -0500340 // Call TI special attention handler
341 rc = tiHandler(nullptr);
342 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500343 }
Ben Tyner970fd4f2020-02-19 13:46:42 -0600344 }
Ben Tyneref320152020-01-09 10:31:23 -0600345
Ben Tyner792f32f2020-06-02 08:50:47 -0500346 // release TI data buffer
347 if (nullptr != tiInfo)
348 {
349 free(tiInfo);
350 }
351
Ben Tyner3fb52e52020-03-31 10:10:07 -0500352 if (RC_SUCCESS != rc)
353 {
Ben Tyner792f32f2020-06-02 08:50:47 -0500354 trace<level::INFO>("Special attn not handled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500355 }
Ben Tyneref320152020-01-09 10:31:23 -0600356
357 return rc;
358}
359
Ben Tynerfb190542020-11-06 09:27:56 -0600360/**
361 * @brief Determine if attention is active and not masked
362 *
363 * Determine whether an attention needs to be handled and trace details of
364 * attention type and whether it is masked or not.
365 *
366 * @param i_val attention status register
367 * @param i_mask attention true mask register
368 * @param i_attn attention type
369 * @param i_proc processor associated with registers
370 *
371 * @return true if attention is active and not masked, otherwise false
372 */
Ben Tyner1965e502020-11-20 10:32:24 -0600373bool activeAttn(uint32_t i_val, uint32_t i_mask, uint32_t i_attn)
Ben Tynerfb190542020-11-06 09:27:56 -0600374{
375 bool rc = false; // assume attn masked and/or inactive
376 bool validAttn = true; // known attention type
377
378 // if attention active
379 if (0 != (i_val & i_attn))
380 {
Ben Tynerfb190542020-11-06 09:27:56 -0600381 std::stringstream ss;
Ben Tynerfb190542020-11-06 09:27:56 -0600382
383 switch (i_attn)
384 {
385 case SBE_ATTN:
386 ss << "SBE attn";
387 break;
388 case CHECKSTOP_ATTN:
389 ss << "Checkstop attn";
390 break;
391 case SPECIAL_ATTN:
392 ss << "Special attn";
393 break;
394 default:
395 ss << "Unknown attn";
396 validAttn = false;
397 }
398
399 // see if attention is masked
400 if (true == validAttn)
401 {
402 if (0 != (i_mask & i_attn))
403 {
404 rc = true; // attention active and not masked
405 }
406 else
407 {
408 ss << " masked";
409 }
410 }
411
412 trace<level::INFO>(ss.str().c_str()); // commit trace stream
413 }
414
415 return rc;
416}
417
Ben Tyneref320152020-01-09 10:31:23 -0600418} // namespace attn