xref: /openbmc/openpower-proc-control/procedures/phal/thread_stopall.cpp (revision 4d5b5bfe01c5eb83823e2a92d4b1a26455eb87ee)
1 #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>
9 extern "C"
10 {
11 #include <libpdbg.h>
12 }
13 #include <phosphor-logging/log.hpp>
14 
15 namespace openpower
16 {
17 namespace phal
18 {
19 using namespace openpower::pel;
20 using namespace openpower::phal::exception;
21 using 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  */
31 void 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                     // Create informational error log.
93                     createSbeErrorPEL(
94                         "org.open_power.Processor.Error.SbeChipOpFailure",
95                         sbeError, pelAdditionalData, procTarget,
96                         Severity::Informational);
97                 }
98                 else
99                 {
100                     // SBE is not ready to accept chip-ops,
101                     // Skip the request, no additional error handling required.
102                     log<level::INFO>(
103                         fmt::format("threadStopAll: Skipping ({}) on proc({})",
104                                     sbeError.what(),
105                                     pdbg_target_index(procTarget))
106                             .c_str());
107                 }
108                 continue;
109             }
110             log<level::INFO>(
111                 fmt::format("Processor thread stopall completed on proc({})",
112                             pdbg_target_index(procTarget))
113                     .c_str());
114         }
115     }
116     // Capture general exception
117     catch (const std::exception& ex)
118     {
119         // This failure could be related to BMC firmware
120         // Dont throw exception on failure because, need to proceed
121         // further to complete power-off/reboot.
122         log<level::ERR>(
123             fmt::format("threadStopAll: Exception({})", ex.what()).c_str());
124 
125         // To store additional data about ffdc.
126         FFDCData pelAdditionalData;
127 
128         // SRC6 : [0:15] chip position, setting 0xFF to indicate generic fail
129         //        [16:23] command class,  [24:31] Type
130         pelAdditionalData.emplace_back("SRC6",
131                                        std::to_string((0xFF << 16) | cmd));
132         json jsonCalloutDataList;
133         jsonCalloutDataList = json::array();
134         json jsonCalloutData;
135         jsonCalloutData["Procedure"] = "BMC0001";
136         jsonCalloutData["Priority"] = "H";
137         jsonCalloutDataList.emplace_back(jsonCalloutData);
138         openpower::pel::createErrorPEL(
139             "org.open_power.Processor.Error.SbeChipOpFailure",
140             jsonCalloutDataList, pelAdditionalData, Severity::Informational);
141         return;
142     }
143 }
144 
145 REGISTER_PROCEDURE("threadStopAll", threadStopAll)
146 
147 } // namespace phal
148 } // namespace openpower
149