blob: b3a76933a68e169740eaa4b17ee0fed9e442dd6b [file] [log] [blame]
Matt Spinler711d51d2019-11-06 09:36:51 -06001/**
2 * Copyright © 2019 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Matt Spinlerf9bae182019-10-09 13:37:38 -050016#include "src.hpp"
17
Matt Spinler717de422020-06-04 13:10:14 -050018#include "device_callouts.hpp"
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +080019#include "json_utils.hpp"
20#include "paths.hpp"
21#include "pel_values.hpp"
22
Matt Spinlerf9bae182019-10-09 13:37:38 -050023#include <phosphor-logging/log.hpp>
24
25namespace openpower
26{
27namespace pels
28{
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +080029namespace pv = openpower::pels::pel_values;
30namespace rg = openpower::pels::message;
Matt Spinlerf9bae182019-10-09 13:37:38 -050031using namespace phosphor::logging;
Matt Spinler85f61a62020-06-03 16:28:55 -050032using namespace std::string_literals;
Matt Spinlerf9bae182019-10-09 13:37:38 -050033
Matt Spinler075e5ba2020-02-21 15:46:00 -060034constexpr size_t ccinSize = 4;
35
Matt Spinlerf9bae182019-10-09 13:37:38 -050036void SRC::unflatten(Stream& stream)
37{
38 stream >> _header >> _version >> _flags >> _reserved1B >> _wordCount >>
39 _reserved2B >> _size;
40
41 for (auto& word : _hexData)
42 {
43 stream >> word;
44 }
45
46 _asciiString = std::make_unique<src::AsciiString>(stream);
47
48 if (hasAdditionalSections())
49 {
50 // The callouts section is currently the only extra subsection type
51 _callouts = std::make_unique<src::Callouts>(stream);
52 }
53}
54
Matt Spinler06885452019-11-06 10:35:42 -060055void SRC::flatten(Stream& stream) const
Matt Spinlerf9bae182019-10-09 13:37:38 -050056{
57 stream << _header << _version << _flags << _reserved1B << _wordCount
58 << _reserved2B << _size;
59
60 for (auto& word : _hexData)
61 {
62 stream << word;
63 }
64
65 _asciiString->flatten(stream);
66
67 if (_callouts)
68 {
69 _callouts->flatten(stream);
70 }
71}
72
73SRC::SRC(Stream& pel)
74{
75 try
76 {
77 unflatten(pel);
78 validate();
79 }
80 catch (const std::exception& e)
81 {
82 log<level::ERR>("Cannot unflatten SRC", entry("ERROR=%s", e.what()));
83 _valid = false;
84 }
85}
86
Matt Spinler075e5ba2020-02-21 15:46:00 -060087SRC::SRC(const message::Entry& regEntry, const AdditionalData& additionalData,
88 const DataInterfaceBase& dataIface)
Matt Spinlerbd716f02019-10-15 10:54:11 -050089{
90 _header.id = static_cast<uint16_t>(SectionID::primarySRC);
91 _header.version = srcSectionVersion;
92 _header.subType = srcSectionSubtype;
93 _header.componentID = regEntry.componentID;
94
95 _version = srcVersion;
96
97 _flags = 0;
98 if (regEntry.src.powerFault.value_or(false))
99 {
100 _flags |= powerFaultEvent;
101 }
102
103 _reserved1B = 0;
104
105 _wordCount = numSRCHexDataWords + 1;
106
107 _reserved2B = 0;
108
109 // There are multiple fields encoded in the hex data words.
110 std::for_each(_hexData.begin(), _hexData.end(),
111 [](auto& word) { word = 0; });
Matt Spinler7c619182020-07-27 15:15:11 -0500112
113 // Hex Word 2 Nibbles:
114 // MIGVEPFF
115 // M: Partition dump status = 0
116 // I: System boot state = TODO
117 // G: Partition Boot type = 0
118 // V: BMC dump status = TODO
119 // E: Platform boot mode = 0 (side = temporary, speed = fast)
120 // P: Platform dump status = TODO
121 // FF: SRC format, set below
122
Matt Spinlerbd716f02019-10-15 10:54:11 -0500123 setBMCFormat();
124 setBMCPosition();
Matt Spinler075e5ba2020-02-21 15:46:00 -0600125 setMotherboardCCIN(dataIface);
126
Matt Spinlerbd716f02019-10-15 10:54:11 -0500127 // Fill in the last 4 words from the AdditionalData property contents.
128 setUserDefinedHexWords(regEntry, additionalData);
129
130 _asciiString = std::make_unique<src::AsciiString>(regEntry);
131
Matt Spinler03984582020-04-09 13:17:58 -0500132 addCallouts(regEntry, additionalData, dataIface);
Matt Spinlerbd716f02019-10-15 10:54:11 -0500133
134 _size = baseSRCSize;
135 _size += _callouts ? _callouts->flattenedSize() : 0;
136 _header.size = Section::flattenedSize() + _size;
137
138 _valid = true;
139}
140
141void SRC::setUserDefinedHexWords(const message::Entry& regEntry,
142 const AdditionalData& ad)
143{
144 if (!regEntry.src.hexwordADFields)
145 {
146 return;
147 }
148
149 // Save the AdditionalData value corresponding to the
150 // adName key in _hexData[wordNum].
151 for (const auto& [wordNum, adName] : *regEntry.src.hexwordADFields)
152 {
153 // Can only set words 6 - 9
154 if (!isUserDefinedWord(wordNum))
155 {
Matt Spinler85f61a62020-06-03 16:28:55 -0500156 std::string msg =
157 "SRC user data word out of range: " + std::to_string(wordNum);
158 addDebugData(msg);
Matt Spinlerbd716f02019-10-15 10:54:11 -0500159 continue;
160 }
161
162 auto value = ad.getValue(adName);
163 if (value)
164 {
165 _hexData[getWordIndexFromWordNum(wordNum)] =
166 std::strtoul(value.value().c_str(), nullptr, 0);
167 }
168 else
169 {
Matt Spinler85f61a62020-06-03 16:28:55 -0500170 std::string msg =
171 "Source for user data SRC word not found: " + adName;
172 addDebugData(msg);
Matt Spinlerbd716f02019-10-15 10:54:11 -0500173 }
174 }
175}
176
Matt Spinler075e5ba2020-02-21 15:46:00 -0600177void SRC::setMotherboardCCIN(const DataInterfaceBase& dataIface)
178{
179 uint32_t ccin = 0;
180 auto ccinString = dataIface.getMotherboardCCIN();
181
182 try
183 {
184 if (ccinString.size() == ccinSize)
185 {
186 ccin = std::stoi(ccinString, 0, 16);
187 }
188 }
189 catch (std::exception& e)
190 {
191 log<level::WARNING>("Could not convert motherboard CCIN to a number",
192 entry("CCIN=%s", ccinString.c_str()));
193 return;
194 }
195
196 // Set the first 2 bytes
197 _hexData[1] |= ccin << 16;
198}
199
Matt Spinlerf9bae182019-10-09 13:37:38 -0500200void SRC::validate()
201{
202 bool failed = false;
203
204 if ((header().id != static_cast<uint16_t>(SectionID::primarySRC)) &&
205 (header().id != static_cast<uint16_t>(SectionID::secondarySRC)))
206 {
207 log<level::ERR>("Invalid SRC section ID",
208 entry("ID=0x%X", header().id));
209 failed = true;
210 }
211
212 // Check the version in the SRC, not in the header
Matt Spinlerbd716f02019-10-15 10:54:11 -0500213 if (_version != srcVersion)
Matt Spinlerf9bae182019-10-09 13:37:38 -0500214 {
Matt Spinlerbd716f02019-10-15 10:54:11 -0500215 log<level::ERR>("Invalid SRC version", entry("VERSION=0x%X", _version));
Matt Spinlerf9bae182019-10-09 13:37:38 -0500216 failed = true;
217 }
218
219 _valid = failed ? false : true;
220}
221
Matt Spinler075e5ba2020-02-21 15:46:00 -0600222bool SRC::isBMCSRC() const
223{
224 auto as = asciiString();
225 if (as.length() >= 2)
226 {
227 uint8_t errorType = strtoul(as.substr(0, 2).c_str(), nullptr, 16);
228 return (errorType == static_cast<uint8_t>(SRCType::bmcError) ||
229 errorType == static_cast<uint8_t>(SRCType::powerError));
230 }
231 return false;
232}
233
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800234std::optional<std::string> SRC::getErrorDetails(message::Registry& registry,
235 DetailLevel type,
236 bool toCache) const
237{
238 const std::string jsonIndent(indentLevel, 0x20);
239 std::string errorOut;
Matt Spinler075e5ba2020-02-21 15:46:00 -0600240 if (isBMCSRC())
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800241 {
242 auto entry = registry.lookup("0x" + asciiString().substr(4, 4),
243 rg::LookupType::reasonCode, toCache);
244 if (entry)
245 {
246 errorOut.append(jsonIndent + "\"Error Details\": {\n");
247 auto errorMsg = getErrorMessage(*entry);
248 if (errorMsg)
249 {
250 if (type == DetailLevel::message)
251 {
252 return errorMsg.value();
253 }
254 else
255 {
256 jsonInsert(errorOut, "Message", errorMsg.value(), 2);
257 }
258 }
259 if (entry->src.hexwordADFields)
260 {
261 std::map<size_t, std::string> adFields =
262 entry->src.hexwordADFields.value();
263 for (const auto& hexwordMap : adFields)
264 {
265 jsonInsert(errorOut, hexwordMap.second,
266 getNumberString("0x%X",
267 _hexData[getWordIndexFromWordNum(
268 hexwordMap.first)]),
269 2);
270 }
271 }
272 errorOut.erase(errorOut.size() - 2);
273 errorOut.append("\n");
274 errorOut.append(jsonIndent + "},\n");
275 return errorOut;
276 }
277 }
278 return std::nullopt;
279}
280
281std::optional<std::string>
282 SRC::getErrorMessage(const message::Entry& regEntry) const
283{
284 try
285 {
286 if (regEntry.doc.messageArgSources)
287 {
288 size_t msgLen = regEntry.doc.message.length();
289 char msg[msgLen + 1];
290 strcpy(msg, regEntry.doc.message.c_str());
291 std::vector<uint32_t> argSourceVals;
292 std::string message;
293 const auto& argValues = regEntry.doc.messageArgSources.value();
294 for (size_t i = 0; i < argValues.size(); ++i)
295 {
296 argSourceVals.push_back(_hexData[getWordIndexFromWordNum(
297 argValues[i].back() - '0')]);
298 }
299 const char* msgPointer = msg;
300 while (*msgPointer)
301 {
302 if (*msgPointer == '%')
303 {
304 msgPointer++;
305 size_t wordIndex = *msgPointer - '0';
306 if (isdigit(*msgPointer) && wordIndex >= 1 &&
307 static_cast<uint16_t>(wordIndex) <=
308 argSourceVals.size())
309 {
310 message.append(getNumberString(
311 "0x%X", argSourceVals[wordIndex - 1]));
312 }
313 else
314 {
315 message.append("%" + std::string(1, *msgPointer));
316 }
317 }
318 else
319 {
320 message.push_back(*msgPointer);
321 }
322 msgPointer++;
323 }
324 return message;
325 }
326 else
327 {
328 return regEntry.doc.message;
329 }
330 }
331 catch (const std::exception& e)
332 {
333 log<level::ERR>("Cannot get error message from registry entry",
334 entry("ERROR=%s", e.what()));
335 }
336 return std::nullopt;
337}
338
339std::optional<std::string> SRC::getCallouts() const
340{
341 if (!_callouts)
342 {
343 return std::nullopt;
344 }
345 std::string printOut;
346 const std::string jsonIndent(indentLevel, 0x20);
347 const auto& callout = _callouts->callouts();
348 const auto& compDescrp = pv::failingComponentType;
349 printOut.append(jsonIndent + "\"Callout Section\": {\n");
350 jsonInsert(printOut, "Callout Count", std::to_string(callout.size()), 2);
351 printOut.append(jsonIndent + jsonIndent + "\"Callouts\": [");
352 for (auto& entry : callout)
353 {
354 printOut.append("{\n");
355 if (entry->fruIdentity())
356 {
357 jsonInsert(
358 printOut, "FRU Type",
359 compDescrp.at(entry->fruIdentity()->failingComponentType()), 3);
360 jsonInsert(printOut, "Priority",
361 pv::getValue(entry->priority(),
362 pel_values::calloutPriorityValues),
363 3);
364 if (!entry->locationCode().empty())
365 {
366 jsonInsert(printOut, "Location Code", entry->locationCode(), 3);
367 }
368 if (entry->fruIdentity()->getPN().has_value())
369 {
370 jsonInsert(printOut, "Part Number",
371 entry->fruIdentity()->getPN().value(), 3);
372 }
373 if (entry->fruIdentity()->getMaintProc().has_value())
374 {
375 jsonInsert(printOut, "Procedure Number",
376 entry->fruIdentity()->getMaintProc().value(), 3);
377 if (pv::procedureDesc.find(
378 entry->fruIdentity()->getMaintProc().value()) !=
379 pv::procedureDesc.end())
380 {
381 jsonInsert(
382 printOut, "Description",
383 pv::procedureDesc.at(
384 entry->fruIdentity()->getMaintProc().value()),
385 3);
386 }
387 }
388 if (entry->fruIdentity()->getCCIN().has_value())
389 {
390 jsonInsert(printOut, "CCIN",
391 entry->fruIdentity()->getCCIN().value(), 3);
392 }
393 if (entry->fruIdentity()->getSN().has_value())
394 {
395 jsonInsert(printOut, "Serial Number",
396 entry->fruIdentity()->getSN().value(), 3);
397 }
398 }
399 if (entry->pceIdentity())
400 {
401 const auto& pceIdentMtms = entry->pceIdentity()->mtms();
402 if (!pceIdentMtms.machineTypeAndModel().empty())
403 {
404 jsonInsert(printOut, "PCE MTMS",
405 pceIdentMtms.machineTypeAndModel() + "_" +
406 pceIdentMtms.machineSerialNumber(),
407 3);
408 }
409 if (!entry->pceIdentity()->enclosureName().empty())
410 {
411 jsonInsert(printOut, "PCE Name",
412 entry->pceIdentity()->enclosureName(), 3);
413 }
414 }
415 if (entry->mru())
416 {
417 const auto& mruCallouts = entry->mru()->mrus();
418 std::string mruId;
419 for (auto& element : mruCallouts)
420 {
421 if (!mruId.empty())
422 {
423 mruId.append(", " + getNumberString("%08X", element.id));
424 }
425 else
426 {
427 mruId.append(getNumberString("%08X", element.id));
428 }
429 }
430 jsonInsert(printOut, "MRU Id", mruId, 3);
431 }
432 printOut.erase(printOut.size() - 2);
433 printOut.append("\n" + jsonIndent + jsonIndent + "}, ");
434 };
435 printOut.erase(printOut.size() - 2);
436 printOut.append("]\n" + jsonIndent + "}");
437 return printOut;
438}
439
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800440std::optional<std::string> SRC::getJSON(message::Registry& registry) const
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800441{
442 std::string ps;
Harisuddin Mohamed Isabebeb942020-03-12 17:12:24 +0800443 jsonInsert(ps, pv::sectionVer, getNumberString("%d", _header.version), 1);
444 jsonInsert(ps, pv::subSection, getNumberString("%d", _header.subType), 1);
445 jsonInsert(ps, pv::createdBy, getNumberString("0x%X", _header.componentID),
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800446 1);
447 jsonInsert(ps, "SRC Version", getNumberString("0x%02X", _version), 1);
Harisuddin Mohamed Isac32e5512020-02-06 18:05:21 +0800448 jsonInsert(ps, "SRC Format", getNumberString("0x%02X", _hexData[0] & 0xFF),
449 1);
450 jsonInsert(ps, "Virtual Progress SRC",
451 pv::boolString.at(_flags & virtualProgressSRC), 1);
452 jsonInsert(ps, "I5/OS Service Event Bit",
453 pv::boolString.at(_flags & i5OSServiceEventBit), 1);
454 jsonInsert(ps, "Hypervisor Dump Initiated",
455 pv::boolString.at(_flags & hypDumpInit), 1);
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800456 jsonInsert(ps, "Power Control Net Fault",
457 pv::boolString.at(isPowerFaultEvent()), 1);
Matt Spinler075e5ba2020-02-21 15:46:00 -0600458
459 if (isBMCSRC())
460 {
461 std::string ccinString;
462 uint32_t ccin = _hexData[1] >> 16;
463
464 if (ccin)
465 {
466 ccinString = getNumberString("%04X", ccin);
467 }
468 // The PEL spec calls it a backplane, so call it that here.
469 jsonInsert(ps, "Backplane CCIN", ccinString, 1);
470 }
471
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800472 auto errorDetails = getErrorDetails(registry, DetailLevel::json, true);
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800473 if (errorDetails)
474 {
475 ps.append(errorDetails.value());
476 }
477 jsonInsert(ps, "Valid Word Count", getNumberString("0x%02X", _wordCount),
478 1);
479 std::string refcode = asciiString();
Harisuddin Mohamed Isafecaa572020-03-11 16:04:50 +0800480 std::string extRefcode;
481 size_t pos = refcode.find(0x20);
482 if (pos != std::string::npos)
483 {
484 size_t nextPos = refcode.find_first_not_of(0x20, pos);
485 if (nextPos != std::string::npos)
486 {
487 extRefcode = trimEnd(refcode.substr(nextPos));
488 }
489 refcode.erase(pos);
490 }
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800491 jsonInsert(ps, "Reference Code", refcode, 1);
Harisuddin Mohamed Isafecaa572020-03-11 16:04:50 +0800492 if (!extRefcode.empty())
493 {
494 jsonInsert(ps, "Extended Reference Code", extRefcode, 1);
495 }
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800496 for (size_t i = 2; i <= _wordCount; i++)
497 {
498 jsonInsert(
499 ps, "Hex Word " + std::to_string(i),
500 getNumberString("%08X", _hexData[getWordIndexFromWordNum(i)]), 1);
501 }
502 auto calloutJson = getCallouts();
503 if (calloutJson)
504 {
505 ps.append(calloutJson.value());
506 }
507 else
508 {
509 ps.erase(ps.size() - 2);
510 }
511 return ps;
512}
513
Matt Spinler03984582020-04-09 13:17:58 -0500514void SRC::addCallouts(const message::Entry& regEntry,
515 const AdditionalData& additionalData,
Matt Spinlered046852020-03-13 13:58:15 -0500516 const DataInterfaceBase& dataIface)
517{
518 auto item = additionalData.getValue("CALLOUT_INVENTORY_PATH");
519 if (item)
520 {
Matt Spinleraf191c72020-06-04 11:35:13 -0500521 addInventoryCallout(*item, std::nullopt, std::nullopt, dataIface);
Matt Spinlered046852020-03-13 13:58:15 -0500522 }
523
Matt Spinler717de422020-06-04 13:10:14 -0500524 addDevicePathCallouts(additionalData, dataIface);
Matt Spinler03984582020-04-09 13:17:58 -0500525
526 if (regEntry.callouts)
527 {
528 addRegistryCallouts(regEntry, additionalData, dataIface);
529 }
Matt Spinlered046852020-03-13 13:58:15 -0500530}
531
532void SRC::addInventoryCallout(const std::string& inventoryPath,
Matt Spinleraf191c72020-06-04 11:35:13 -0500533 const std::optional<CalloutPriority>& priority,
534 const std::optional<std::string>& locationCode,
Matt Spinlered046852020-03-13 13:58:15 -0500535 const DataInterfaceBase& dataIface)
536{
537 std::string locCode;
538 std::string fn;
539 std::string ccin;
540 std::string sn;
541 std::unique_ptr<src::Callout> callout;
542
Matt Spinlered046852020-03-13 13:58:15 -0500543 try
544 {
Matt Spinleraf191c72020-06-04 11:35:13 -0500545 // Use the passed in location code if there otherwise look it up
546 if (locationCode)
547 {
548 locCode = *locationCode;
549 }
550 else
551 {
552 locCode = dataIface.getLocationCode(inventoryPath);
553 }
Matt Spinlered046852020-03-13 13:58:15 -0500554
Matt Spinler9b90e2a2020-04-14 10:59:04 -0500555 try
556 {
557 dataIface.getHWCalloutFields(inventoryPath, fn, ccin, sn);
558
Matt Spinleraf191c72020-06-04 11:35:13 -0500559 CalloutPriority p =
560 priority ? priority.value() : CalloutPriority::high;
561
562 callout = std::make_unique<src::Callout>(p, locCode, fn, ccin, sn);
Matt Spinler9b90e2a2020-04-14 10:59:04 -0500563 }
564 catch (const SdBusError& e)
565 {
Matt Spinler85f61a62020-06-03 16:28:55 -0500566 std::string msg =
567 "No VPD found for " + inventoryPath + ": " + e.what();
568 addDebugData(msg);
Matt Spinler9b90e2a2020-04-14 10:59:04 -0500569
570 // Just create the callout with empty FRU fields
571 callout = std::make_unique<src::Callout>(CalloutPriority::high,
572 locCode, fn, ccin, sn);
573 }
Matt Spinlered046852020-03-13 13:58:15 -0500574 }
575 catch (const SdBusError& e)
576 {
Matt Spinler85f61a62020-06-03 16:28:55 -0500577 std::string msg = "Could not get location code for " + inventoryPath +
578 ": " + e.what();
579 addDebugData(msg);
Matt Spinlered046852020-03-13 13:58:15 -0500580
Matt Spinler9b90e2a2020-04-14 10:59:04 -0500581 // If this were to happen, people would have to look in the UserData
582 // section that contains CALLOUT_INVENTORY_PATH to see what failed.
Matt Spinlered046852020-03-13 13:58:15 -0500583 callout = std::make_unique<src::Callout>(CalloutPriority::high,
Matt Spinlera27e2e52020-04-09 11:06:11 -0500584 "no_vpd_for_fru");
Matt Spinlered046852020-03-13 13:58:15 -0500585 }
586
Matt Spinler9b90e2a2020-04-14 10:59:04 -0500587 createCalloutsObject();
Matt Spinlered046852020-03-13 13:58:15 -0500588 _callouts->addCallout(std::move(callout));
Matt Spinler03984582020-04-09 13:17:58 -0500589}
Matt Spinlered046852020-03-13 13:58:15 -0500590
Matt Spinler03984582020-04-09 13:17:58 -0500591void SRC::addRegistryCallouts(const message::Entry& regEntry,
592 const AdditionalData& additionalData,
593 const DataInterfaceBase& dataIface)
594{
595 try
596 {
Matt Spinler6ea4d5f2020-05-20 13:31:07 -0500597 auto systemNames = dataIface.getSystemNames();
Matt Spinler03984582020-04-09 13:17:58 -0500598
599 auto regCallouts = message::Registry::getCallouts(
Matt Spinler6ea4d5f2020-05-20 13:31:07 -0500600 regEntry.callouts.value(), systemNames, additionalData);
Matt Spinler03984582020-04-09 13:17:58 -0500601
602 for (const auto& regCallout : regCallouts)
603 {
604 addRegistryCallout(regCallout, dataIface);
605 }
606 }
607 catch (std::exception& e)
608 {
Matt Spinler85f61a62020-06-03 16:28:55 -0500609 std::string msg =
610 "Error parsing PEL message registry callout JSON: "s + e.what();
611 addDebugData(msg);
Matt Spinler03984582020-04-09 13:17:58 -0500612 }
613}
614
615void SRC::addRegistryCallout(const message::RegistryCallout& regCallout,
616 const DataInterfaceBase& dataIface)
617{
618 std::unique_ptr<src::Callout> callout;
Matt Spinler03984582020-04-09 13:17:58 -0500619 auto locCode = regCallout.locCode;
620
Matt Spinleraf191c72020-06-04 11:35:13 -0500621 if (!locCode.empty())
622 {
623 try
624 {
625 locCode = dataIface.expandLocationCode(locCode, 0);
626 }
627 catch (const std::exception& e)
628 {
629 auto msg =
630 "Unable to expand location code " + locCode + ": " + e.what();
631 addDebugData(msg);
632 return;
633 }
634 }
635
Matt Spinler03984582020-04-09 13:17:58 -0500636 // Via the PEL values table, get the priority enum.
637 // The schema will have validated the priority was a valid value.
638 auto priorityIt =
639 pv::findByName(regCallout.priority, pv::calloutPriorityValues);
640 assert(priorityIt != pv::calloutPriorityValues.end());
641 auto priority =
642 static_cast<CalloutPriority>(std::get<pv::fieldValuePos>(*priorityIt));
643
644 if (!regCallout.procedure.empty())
645 {
646 // Procedure callout
647 callout =
648 std::make_unique<src::Callout>(priority, regCallout.procedure);
649 }
650 else if (!regCallout.symbolicFRU.empty())
651 {
652 // Symbolic FRU callout
653 callout = std::make_unique<src::Callout>(
654 priority, regCallout.symbolicFRU, locCode, false);
655 }
656 else if (!regCallout.symbolicFRUTrusted.empty())
657 {
658 // Symbolic FRU with trusted location code callout
659
660 // The registry wants it to be trusted, but that requires a valid
661 // location code for it to actually be.
662 callout = std::make_unique<src::Callout>(
663 priority, regCallout.symbolicFRUTrusted, locCode, !locCode.empty());
664 }
665 else
666 {
Matt Spinleraf191c72020-06-04 11:35:13 -0500667 // A hardware callout
668 std::string inventoryPath;
669
670 try
671 {
672 // Get the inventory item from the unexpanded location code
673 inventoryPath =
Matt Spinler2f9225a2020-08-05 12:58:49 -0500674 dataIface.getInventoryFromLocCode(regCallout.locCode, 0, false);
Matt Spinleraf191c72020-06-04 11:35:13 -0500675 }
676 catch (const std::exception& e)
677 {
678 std::string msg =
679 "Unable to get inventory path from location code: " + locCode +
680 ": " + e.what();
681 addDebugData(msg);
682 return;
683 }
684
685 addInventoryCallout(inventoryPath, priority, locCode, dataIface);
Matt Spinler03984582020-04-09 13:17:58 -0500686 }
687
688 if (callout)
689 {
690 createCalloutsObject();
691 _callouts->addCallout(std::move(callout));
692 }
693}
Matt Spinlered046852020-03-13 13:58:15 -0500694
Matt Spinler717de422020-06-04 13:10:14 -0500695void SRC::addDevicePathCallouts(const AdditionalData& additionalData,
696 const DataInterfaceBase& dataIface)
697{
698 std::vector<device_callouts::Callout> callouts;
699 auto i2cBus = additionalData.getValue("CALLOUT_IIC_BUS");
700 auto i2cAddr = additionalData.getValue("CALLOUT_IIC_ADDR");
701 auto devPath = additionalData.getValue("CALLOUT_DEVICE_PATH");
702
703 // A device callout contains either:
704 // * CALLOUT_ERRNO, CALLOUT_DEVICE_PATH
705 // * CALLOUT_ERRNO, CALLOUT_IIC_BUS, CALLOUT_IIC_ADDR
706 // We don't care about the errno.
707
708 if (devPath)
709 {
710 try
711 {
712 callouts = device_callouts::getCallouts(*devPath,
713 dataIface.getSystemNames());
714 }
715 catch (const std::exception& e)
716 {
717 addDebugData(e.what());
718 callouts.clear();
719 }
720 }
721 else if (i2cBus && i2cAddr)
722 {
723 size_t bus;
724 uint8_t address;
725
726 try
727 {
728 // If /dev/i2c- is prepended, remove it
729 if (i2cBus->find("/dev/i2c-") != std::string::npos)
730 {
731 *i2cBus = i2cBus->substr(9);
732 }
733
734 bus = stoul(*i2cBus, nullptr, 0);
735 address = stoul(*i2cAddr, nullptr, 0);
736 }
737 catch (const std::exception& e)
738 {
739 std::string msg = "Invalid CALLOUT_IIC_BUS " + *i2cBus +
740 " or CALLOUT_IIC_ADDR " + *i2cAddr +
741 " in AdditionalData property";
742 addDebugData(msg);
743 return;
744 }
745
746 try
747 {
748 callouts = device_callouts::getI2CCallouts(
749 bus, address, dataIface.getSystemNames());
750 }
751 catch (const std::exception& e)
752 {
753 addDebugData(e.what());
754 callouts.clear();
755 }
756 }
757
758 for (const auto& callout : callouts)
759 {
760 // The priority shouldn't be invalid, but check just in case.
761 CalloutPriority priority = CalloutPriority::high;
762
763 if (!callout.priority.empty())
764 {
765 auto p = pel_values::findByValue(
766 static_cast<uint32_t>(callout.priority[0]),
767 pel_values::calloutPriorityValues);
768
769 if (p != pel_values::calloutPriorityValues.end())
770 {
771 priority = static_cast<CalloutPriority>(callout.priority[0]);
772 }
773 else
774 {
775 std::string msg =
776 "Invalid priority found in dev callout JSON: " +
777 callout.priority[0];
778 addDebugData(msg);
779 }
780 }
781
782 try
783 {
Matt Spinler2f9225a2020-08-05 12:58:49 -0500784 auto inventoryPath = dataIface.getInventoryFromLocCode(
785 callout.locationCode, 0, false);
Matt Spinler717de422020-06-04 13:10:14 -0500786
787 addInventoryCallout(inventoryPath, priority, std::nullopt,
788 dataIface);
789 }
790 catch (const std::exception& e)
791 {
792 std::string msg =
793 "Unable to get inventory path from location code: " +
794 callout.locationCode + ": " + e.what();
795 addDebugData(msg);
796 }
797
798 // Until the code is there to convert these MRU value strings to
799 // the official MRU values in the callout objects, just store
800 // the MRU name in the debug UserData section.
801 if (!callout.mru.empty())
802 {
803 std::string msg = "MRU: " + callout.mru;
804 addDebugData(msg);
805 }
806
807 // getCallouts() may have generated some debug data it stored
808 // in a callout object. Save it as well.
809 if (!callout.debug.empty())
810 {
811 addDebugData(callout.debug);
812 }
813 }
814}
815
Matt Spinlerf9bae182019-10-09 13:37:38 -0500816} // namespace pels
817} // namespace openpower