blob: 829b44f554514d22ef291117d2bcdb4238f93fa7 [file] [log] [blame]
Jason M. Billsd711cc82020-12-04 16:46:39 -08001/*
2// Copyright (c) 2021 Intel 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*/
16#pragma once
17#include <sdbusplus/asio/object_server.hpp>
18
19#include <iostream>
20
21namespace host_error_monitor
22{
Jason M. Bills8fa1c962020-12-10 14:33:56 -080023using Association = std::tuple<std::string, std::string, std::string>;
24
Jason M. Billsd711cc82020-12-04 16:46:39 -080025bool hostIsOff();
26
27void startPowerCycle(std::shared_ptr<sdbusplus::asio::connection> conn)
28{
29 conn->async_method_call(
30 [](boost::system::error_code ec) {
31 if (ec)
32 {
33 std::cerr << "failed to set Chassis State\n";
34 }
35 },
36 "xyz.openbmc_project.State.Chassis",
37 "/xyz/openbmc_project/state/chassis0",
38 "org.freedesktop.DBus.Properties", "Set",
39 "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition",
40 std::variant<std::string>{
41 "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"});
42}
43
44void startWarmReset(std::shared_ptr<sdbusplus::asio::connection> conn)
45{
46 conn->async_method_call(
47 [](boost::system::error_code ec) {
48 if (ec)
49 {
50 std::cerr << "failed to set Host State\n";
51 }
52 },
53 "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
54 "org.freedesktop.DBus.Properties", "Set",
55 "xyz.openbmc_project.State.Host", "RequestedHostTransition",
56 std::variant<std::string>{
57 "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"});
58}
59
60void startCrashdumpAndRecovery(
61 std::shared_ptr<sdbusplus::asio::connection> conn, bool recoverSystem,
62 const std::string& triggerType)
63{
64 static bool recover;
65 recover = recoverSystem;
66 std::cerr << "Starting crashdump\n";
67 static std::shared_ptr<sdbusplus::bus::match::match> crashdumpCompleteMatch;
68
69 if (!crashdumpCompleteMatch)
70 {
71 crashdumpCompleteMatch = std::make_shared<sdbusplus::bus::match::match>(
72 *conn,
73 "type='signal',interface='com.intel.crashdump.Stored',member='"
74 "CrashdumpComplete'",
75 [conn](sdbusplus::message::message& msg) {
76 std::cerr << "Crashdump completed\n";
77 if (recover)
78 {
79 std::cerr << "Recovering the system\n";
80 startWarmReset(conn);
81 }
82 crashdumpCompleteMatch.reset();
83 });
84 }
85
86 conn->async_method_call(
87 [](boost::system::error_code ec) {
88 if (ec)
89 {
90 std::cerr << "failed to start Crashdump\n";
91 }
92 },
93 "com.intel.crashdump", "/com/intel/crashdump",
94 "com.intel.crashdump.Stored", "GenerateStoredLog", triggerType);
95}
96
Jason M. Bills0e06b842020-10-02 16:30:06 -070097static inline bool peciError(EPECIStatus peciStatus, uint8_t cc)
98{
99 return (
100 peciStatus != PECI_CC_SUCCESS ||
101 (cc != PECI_DEV_CC_SUCCESS && cc != PECI_DEV_CC_FATAL_MCA_DETECTED));
102}
103
104static void printPECIError(const std::string& reg, const size_t addr,
105 const EPECIStatus peciStatus, const size_t cc)
106{
107 std::cerr << "Failed to read " << reg << " on CPU address " << addr
108 << ". Error: " << peciStatus << ": cc: 0x" << std::hex << cc
109 << "\n";
110}
111
Jason M. Bills47008522020-10-07 16:42:34 -0700112static void beep(std::shared_ptr<sdbusplus::asio::connection> conn,
113 const uint8_t& beepPriority)
114{
115 conn->async_method_call(
116 [](boost::system::error_code ec) {
117 if (ec)
118 {
119 std::cerr << "beep returned error with "
120 "async_method_call (ec = "
121 << ec << ")\n";
122 return;
123 }
124 },
125 "xyz.openbmc_project.BeepCode", "/xyz/openbmc_project/BeepCode",
126 "xyz.openbmc_project.BeepCode", "Beep", uint8_t(beepPriority));
127}
128
Jason M. Billsd711cc82020-12-04 16:46:39 -0800129} // namespace host_error_monitor