blob: f34dd2e8c89fc72f111c57175ce48ecb7f060dcc [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
48/**
Ben Tyneref320152020-01-09 10:31:23 -060049 * @brief The main attention handler logic
Ben Tyner970fd4f2020-02-19 13:46:42 -060050 *
51 * @param i_breakpoints true = breakpoint special attn handling enabled
Ben Tyneref320152020-01-09 10:31:23 -060052 */
Ben Tyner3fb52e52020-03-31 10:10:07 -050053void attnHandler(Config* i_config)
Ben Tyneref320152020-01-09 10:31:23 -060054{
Ben Tynerb481d902020-03-05 10:24:23 -060055 // Vector of active attentions to be handled
56 std::vector<Attention> active_attentions;
57
Ben Tyneref320152020-01-09 10:31:23 -060058 uint32_t isr_val, isr_mask;
59 uint32_t proc;
60
61 // loop through processors looking for active attentions
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050062 trace<level::INFO>("Attention handler started");
Ben Tyner117af992020-05-22 13:32:11 -050063
Ben Tyneref320152020-01-09 10:31:23 -060064 pdbg_target* target;
Ben Tyner5e622d82020-09-11 10:10:24 -050065 pdbg_for_each_class_target("proc", target)
Ben Tyneref320152020-01-09 10:31:23 -060066 {
67 if (PDBG_TARGET_ENABLED == pdbg_target_probe(target))
68 {
69 proc = pdbg_target_index(target); // get processor number
70
71 std::stringstream ss; // log message stream
Ben Tyner9dbab8b2020-03-31 08:55:23 -050072 ss << "checking processor " << proc;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050073 trace<level::INFO>(ss.str().c_str());
Ben Tyneref320152020-01-09 10:31:23 -060074
Ben Tyner5e622d82020-09-11 10:10:24 -050075 // The processor FSI target is required for CFAM read
76 char path[16];
77 sprintf(path, "/proc%d/fsi", proc);
78 pdbg_target* attnTarget = pdbg_target_from_path(nullptr, path);
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050079
Ben Tyner5e622d82020-09-11 10:10:24 -050080 if (PDBG_TARGET_ENABLED == pdbg_target_probe(attnTarget))
Ben Tyneref320152020-01-09 10:31:23 -060081 {
Ben Tyner5e622d82020-09-11 10:10:24 -050082 // get active attentions on processor
83 if (RC_SUCCESS != fsi_read(attnTarget, 0x1007, &isr_val))
Ben Tyneref320152020-01-09 10:31:23 -060084 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050085 // event
86 eventAttentionFail(RC_CFAM_ERROR);
87
88 // trace
Ben Tyner5e622d82020-09-11 10:10:24 -050089 trace<level::INFO>("Error! cfam read 0x1007 FAILED");
Ben Tyneref320152020-01-09 10:31:23 -060090 }
91 else
92 {
93 std::stringstream ss; // log message stream
Ben Tyner5e622d82020-09-11 10:10:24 -050094 ss << "cfam 0x1007 = 0x";
Ben Tyneref320152020-01-09 10:31:23 -060095 ss << std::hex << std::setw(8) << std::setfill('0');
Ben Tyner5e622d82020-09-11 10:10:24 -050096 ss << isr_val;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050097 trace<level::INFO>(ss.str().c_str());
Ben Tyneref320152020-01-09 10:31:23 -060098
Ben Tyner5e622d82020-09-11 10:10:24 -050099 // get interrupt enabled special attentions mask
100 if (RC_SUCCESS != fsi_read(attnTarget, 0x100d, &isr_mask))
Ben Tyneref320152020-01-09 10:31:23 -0600101 {
Ben Tyner5e622d82020-09-11 10:10:24 -0500102 // event
103 eventAttentionFail(RC_CFAM_ERROR);
Ben Tyneref320152020-01-09 10:31:23 -0600104
Ben Tyner5e622d82020-09-11 10:10:24 -0500105 // trace
106 trace<level::INFO>("Error! cfam read 0x100d FAILED");
Ben Tyneref320152020-01-09 10:31:23 -0600107 }
Ben Tyner5e622d82020-09-11 10:10:24 -0500108 else
109 {
110 // CFAM 0x100d is expected to have bits set
111 // corresponding to attentions that can generate an
112 // attention interrupt. We will trace this register
113 // value to help debug cases where the attention handler
114 // was invoked unexpectedly.
Ben Tyneref320152020-01-09 10:31:23 -0600115
Ben Tyner5e622d82020-09-11 10:10:24 -0500116 std::stringstream ss; // log message stream
117 ss << "cfam 0x100d = 0x";
118 ss << std::hex << std::setw(8) << std::setfill('0');
119 ss << isr_mask;
120 trace<level::INFO>(ss.str().c_str());
121
122 // bit 0 on "left": bit 30 = SBE vital attention
123 if (isr_val & 0x00000002)
124 {
125 active_attentions.emplace_back(Attention::Vital,
126 handleVital, target,
127 i_config);
128 }
129
130 // bit 0 on "left": bit 1 = checkstop
131 if (isr_val & 0x40000000)
132 {
133 active_attentions.emplace_back(Attention::Checkstop,
134 handleCheckstop,
135 target, i_config);
136 }
137
138 // bit 0 on "left": bit 2 = special attention
139 if (isr_val & 0x20000000)
140 {
141 active_attentions.emplace_back(Attention::Special,
142 handleSpecial,
143 target, i_config);
144 }
145 } // cfam 0x100d valid
146 } // cfam 0x1007 valid
147 } // proc target enabled
148 } // fsi target enabled
149 } // next processor
Ben Tyneref320152020-01-09 10:31:23 -0600150
Ben Tynerb481d902020-03-05 10:24:23 -0600151 // convert to heap, highest priority is at front
152 if (!std::is_heap(active_attentions.begin(), active_attentions.end()))
153 {
154 std::make_heap(active_attentions.begin(), active_attentions.end());
155 }
156
157 // call the attention handler until one is handled or all were attempted
158 while (false == active_attentions.empty())
159 {
160 // handle highest priority attention, done if successful
161 if (RC_SUCCESS == active_attentions.front().handle())
162 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500163 // an attention was handled so we are done
Ben Tynerb481d902020-03-05 10:24:23 -0600164 break;
165 }
166
167 // move attention to back of vector
168 std::pop_heap(active_attentions.begin(), active_attentions.end());
169
170 // remove attention from vector
171 active_attentions.pop_back();
172 }
Ben Tyneref320152020-01-09 10:31:23 -0600173}
174
175/**
176 * @brief Handle SBE vital attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500177 *
178 * @param i_attention Attention object
179 * @return 0 indicates that the vital attention was successfully handled
180 * 1 indicates that the vital attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600181 */
Ben Tynerb481d902020-03-05 10:24:23 -0600182int handleVital(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600183{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500184 int rc = RC_SUCCESS; // assume vital handled
Ben Tyneref320152020-01-09 10:31:23 -0600185
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500186 trace<level::INFO>("vital handler started");
187
Ben Tyner3fb52e52020-03-31 10:10:07 -0500188 // if vital handling enabled, handle vital attention
189 if (false == (i_attention->getConfig()->getFlag(enVital)))
190 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500191 trace<level::INFO>("vital handling disabled");
Ben Tyner792f32f2020-06-02 08:50:47 -0500192 rc = RC_NOT_HANDLED;
Ben Tyner3fb52e52020-03-31 10:10:07 -0500193 }
194 else
Ben Tyneref320152020-01-09 10:31:23 -0600195 {
Ben Tyner792f32f2020-06-02 08:50:47 -0500196 eventVital();
Ben Tyneref320152020-01-09 10:31:23 -0600197 }
198
199 return rc;
200}
201
202/**
203 * @brief Handle checkstop attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500204 *
205 * @param i_attention Attention object
206 * @return 0 indicates that the checkstop attention was successfully handled
207 * 1 indicates that the checkstop attention was NOT successfully
208 * handled.
Ben Tyneref320152020-01-09 10:31:23 -0600209 */
Ben Tynerb481d902020-03-05 10:24:23 -0600210int handleCheckstop(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600211{
Ben Tyner3fb52e52020-03-31 10:10:07 -0500212 int rc = RC_SUCCESS; // assume checkstop handled
Ben Tyneref320152020-01-09 10:31:23 -0600213
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500214 trace<level::INFO>("checkstop handler started");
215
Ben Tyner3fb52e52020-03-31 10:10:07 -0500216 // if checkstop handling enabled, handle checkstop attention
217 if (false == (i_attention->getConfig()->getFlag(enCheckstop)))
218 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500219 trace<level::INFO>("Checkstop handling disabled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500220 }
221 else
222 {
Zane Shelley9fb73932020-09-15 13:34:57 -0500223 // Look for any attentions found in hardware. This will generate and
224 // comment a PEL if any errors are found.
225 if (true != analyzer::analyzeHardware())
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500226 {
227 rc = RC_ANALYZER_ERROR;
228 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500229 }
Ben Tyneref320152020-01-09 10:31:23 -0600230
Ben Tyneref320152020-01-09 10:31:23 -0600231 return rc;
232}
233
234/**
235 * @brief Handle special attention
Ben Tyner3fb52e52020-03-31 10:10:07 -0500236 *
237 * @param i_attention Attention object
238 * @return 0 indicates that the special attention was successfully handled
239 * 1 indicates that the special attention was NOT successfully handled
Ben Tyneref320152020-01-09 10:31:23 -0600240 */
Ben Tynerb481d902020-03-05 10:24:23 -0600241int handleSpecial(Attention* i_attention)
Ben Tyneref320152020-01-09 10:31:23 -0600242{
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500243 int rc = RC_SUCCESS; // assume special attention handled
Ben Tyneref320152020-01-09 10:31:23 -0600244
Ben Tyner792f32f2020-06-02 08:50:47 -0500245 // The TI infor chipop will give us a pointer to the TI info data
Ben Tyner98430b32020-08-19 19:14:02 -0500246 uint8_t* tiInfo = nullptr; // ptr to TI info data
247 uint32_t tiInfoLen = 0; // length of TI info data
248 pdbg_target* attnProc = i_attention->getTarget(); // proc with attention
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500249
Ben Tyner98430b32020-08-19 19:14:02 -0500250 if (attnProc != nullptr)
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500251 {
Ben Tyner98430b32020-08-19 19:14:02 -0500252 // The processor PIB target is required for get TI info chipop
253 char path[16];
254 sprintf(path, "/proc%d/pib", pdbg_target_index(attnProc));
255 pdbg_target* tiInfoTarget = pdbg_target_from_path(nullptr, path);
256
257 if (nullptr != tiInfoTarget)
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500258 {
Ben Tyner98430b32020-08-19 19:14:02 -0500259 if (PDBG_TARGET_ENABLED == pdbg_target_probe(tiInfoTarget))
260 {
261 trace<level::INFO>("calling sbe_mpipl_get_ti_info");
262 sbe_mpipl_get_ti_info(tiInfoTarget, &tiInfo, &tiInfoLen);
263 if (tiInfo == nullptr)
264 {
265 trace<level::INFO>("TI info data ptr is null after call");
266 }
267 }
Ben Tyner89c0a7a2020-08-07 12:07:35 -0500268 }
269 }
Ben Tyneref320152020-01-09 10:31:23 -0600270
Ben Tyner792f32f2020-06-02 08:50:47 -0500271 // If TI area exists and is marked valid we can assume TI occurred
272 if ((nullptr != tiInfo) && (0 != tiInfo[0]))
Ben Tyner970fd4f2020-02-19 13:46:42 -0600273 {
Ben Tyner98430b32020-08-19 19:14:02 -0500274 trace<level::INFO>("TI info data present and valid");
275
Ben Tyner792f32f2020-06-02 08:50:47 -0500276 TiDataArea* tiDataArea = (TiDataArea*)tiInfo;
Ben Tyner7e6611f2020-02-13 16:42:56 -0600277
Ben Tyner792f32f2020-06-02 08:50:47 -0500278 // trace a few known TI data area values
279 std::stringstream ss; // log message stream
Ben Tyner40717722020-09-23 09:43:20 -0500280
281 ss << "TI data command = " << (int)tiDataArea->command;
Ben Tyner792f32f2020-06-02 08:50:47 -0500282 trace<level::INFO>(ss.str().c_str());
Ben Tyner40717722020-09-23 09:43:20 -0500283 ss.str(std::string());
284
285 ss << "TI data SRC format = " << (int)tiDataArea->srcFormat;
Ben Tyner792f32f2020-06-02 08:50:47 -0500286 trace<level::INFO>(ss.str().c_str());
Ben Tyner40717722020-09-23 09:43:20 -0500287 ss.str(std::string());
288
289 ss << "TI data hb_terminate_type = "
290 << (int)tiDataArea->hbTerminateType;
Ben Tyner792f32f2020-06-02 08:50:47 -0500291 trace<level::INFO>(ss.str().c_str());
Ben Tyner40717722020-09-23 09:43:20 -0500292 ss.str(std::string());
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500293
Ben Tyner792f32f2020-06-02 08:50:47 -0500294 if (true == (i_attention->getConfig()->getFlag(enTerminate)))
295 {
296 trace<level::INFO>("TI (terminate immediately)");
297
298 // Call TI special attention handler
299 rc = tiHandler(tiDataArea);
300 }
Ben Tyner3fb52e52020-03-31 10:10:07 -0500301 }
Ben Tyner792f32f2020-06-02 08:50:47 -0500302 // TI area not valid, assume breakpoint
Ben Tyner3fb52e52020-03-31 10:10:07 -0500303 else
304 {
Ben Tyner98430b32020-08-19 19:14:02 -0500305 trace<level::INFO>("TI info NOT available, assume breakpoint");
306
Ben Tyner3fb52e52020-03-31 10:10:07 -0500307 if (true == (i_attention->getConfig()->getFlag(enBreakpoints)))
308 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -0500309 trace<level::INFO>("breakpoint");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500310
311 // Call the breakpoint special attention handler
312 bpHandler();
Ben Tyner3fb52e52020-03-31 10:10:07 -0500313 }
Ben Tyner970fd4f2020-02-19 13:46:42 -0600314 }
Ben Tyneref320152020-01-09 10:31:23 -0600315
Ben Tyner792f32f2020-06-02 08:50:47 -0500316 // release TI data buffer
317 if (nullptr != tiInfo)
318 {
319 free(tiInfo);
320 }
321
Ben Tyner3fb52e52020-03-31 10:10:07 -0500322 if (RC_SUCCESS != rc)
323 {
Ben Tyner792f32f2020-06-02 08:50:47 -0500324 trace<level::INFO>("Special attn not handled");
Ben Tyner3fb52e52020-03-31 10:10:07 -0500325 }
Ben Tyneref320152020-01-09 10:31:23 -0600326
327 return rc;
328}
329
Ben Tyneref320152020-01-09 10:31:23 -0600330} // namespace attn