blob: ac080f4c04ff3f612b4e88663020aa1c04ffbb45 [file] [log] [blame]
Jayanth Othayoth5f2eaf12021-11-30 11:08:51 -06001#include "extensions/phal/create_pel.hpp"
2#include "extensions/phal/dump_utils.hpp"
3#include "registration.hpp"
4
5#include <attributes_info.H>
6#include <fmt/format.h>
7#include <libphal.H>
8#include <phal_exception.H>
9extern "C"
10{
11#include <libpdbg.h>
12}
13#include <phosphor-logging/log.hpp>
14
15namespace openpower
16{
17namespace phal
18{
19using namespace openpower::pel;
20using namespace openpower::phal::exception;
21using namespace phosphor::logging;
22
23/**
24 * @brief Stop instruction executions on all functional threads in the
25 * host processors.
26 * This procedure is used to stop all threads in the system in
27 * Attempt best case approch. Like issue processor level stopall
28 * chip-op with ignore hardware error mode. Since this function
29 * is used in power-off/error path, ignore the internal error now.
30 */
31void threadStopAll(void)
32{
33 // CMD details based on SBE spec, used for logging purpose
34 constexpr auto SBEFIFO_CMD_CLASS_INSTRUCTION = 0xA700;
35 constexpr auto SBEFIFO_CMD_CONTROL_INSN = 0x01;
36 uint32_t cmd = SBEFIFO_CMD_CLASS_INSTRUCTION | SBEFIFO_CMD_CONTROL_INSN;
37
38 try
39 {
40 // initialize the pdbg.
41 openpower::phal::pdbg::init();
42
43 // Check Host is started.
44 if (!openpower::phal::sbe::isPrimaryIplDone())
45 {
46 log<level::INFO>("threadStopAll : skipping, Host is not running");
47 return;
48 }
49
50 struct pdbg_target* procTarget;
51 ATTR_HWAS_STATE_Type hwasState;
52 pdbg_for_each_class_target("proc", procTarget)
53 {
54 if (DT_GET_PROP(ATTR_HWAS_STATE, procTarget, hwasState))
55 {
56 log<level::ERR>(
57 fmt::format("({})Could not read HWAS_STATE attribute",
58 pdbg_target_path(procTarget))
59 .c_str());
60 continue;
61 }
62 if (!hwasState.functional)
63 {
64 continue;
65 }
66
67 try
68 {
69 openpower::phal::sbe::threadStopProc(procTarget);
70 }
71 catch (const sbeError_t& sbeError)
72 {
73 auto errType = sbeError.errType();
74
75 // Create PEL only for valid SBE reported failures
76 if (errType == SBE_CMD_FAILED)
77 {
78 log<level::ERR>(
79 fmt::format("threadStopAll failed({}) on proc({})",
80 errType, pdbg_target_index(procTarget))
81 .c_str());
82
83 uint32_t index = pdbg_target_index(procTarget);
84 // To store additional data about ffdc.
85 FFDCData pelAdditionalData;
86
87 // SRC6 : [0:15] chip position
88 // [16:23] command class, [24:31] Type
89 pelAdditionalData.emplace_back(
90 "SRC6", std::to_string((index << 16) | cmd));
91
92 createSbeErrorPEL(
93 "org.open_power.Processor.Error.SbeChipOpFailure",
94 sbeError, pelAdditionalData);
95 }
96 else
97 {
98 // SBE is not ready to accept chip-ops,
99 // Skip the request, no additional error handling required.
100 log<level::INFO>(
101 fmt::format("threadStopAll: Skipping ({}) on proc({})",
102 sbeError.what(),
103 pdbg_target_index(procTarget))
104 .c_str());
105 }
106 continue;
107 }
108 log<level::INFO>(
109 fmt::format("Processor thread stopall completed on proc({})",
110 pdbg_target_index(procTarget))
111 .c_str());
112 }
113 }
114 // Capture general exception
115 catch (const std::exception& ex)
116 {
117 // This failure could be related to BMC firmware
118 // Dont throw exception on failure because, need to proceed
119 // further to complete power-off/reboot.
120 log<level::ERR>(
121 fmt::format("threadStopAll: Exception({})", ex.what()).c_str());
122
123 // To store additional data about ffdc.
124 FFDCData pelAdditionalData;
125
126 // SRC6 : [0:15] chip position, setting 0xFF to indicate generic fail
127 // [16:23] command class, [24:31] Type
128 pelAdditionalData.emplace_back("SRC6",
129 std::to_string((0xFF << 16) | cmd));
130 json jsonCalloutDataList;
131 jsonCalloutDataList = json::array();
132 json jsonCalloutData;
133 jsonCalloutData["Procedure"] = "BMC0001";
134 jsonCalloutData["Priority"] = "H";
135 jsonCalloutDataList.emplace_back(jsonCalloutData);
136 openpower::pel::createErrorPEL(
137 "org.open_power.Processor.Error.SbeChipOpFailure",
138 jsonCalloutDataList, pelAdditionalData);
139 return;
140 }
141}
142
143REGISTER_PROCEDURE("threadStopAll", threadStopAll)
144
145} // namespace phal
146} // namespace openpower