blob: 5c3d07ca79b21d54619fac5d1f6924a4f2f288ce [file] [log] [blame]
Jason M. Bills98a38472020-09-22 13:34:33 -07001/*
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 <systemd/sd-journal.h>
18
19#include <error_monitors/base_gpio_poll_monitor.hpp>
20#include <host_error_monitor.hpp>
21#include <sdbusplus/asio/object_server.hpp>
22
23#include <iostream>
24
25namespace host_error_monitor::smi_monitor
26{
27static constexpr bool debug = false;
28
29class SMIMonitor :
30 public host_error_monitor::base_gpio_poll_monitor::BaseGPIOPollMonitor
31{
32 const static host_error_monitor::base_gpio_poll_monitor::AssertValue
33 assertValue =
34 host_error_monitor::base_gpio_poll_monitor::AssertValue::lowAssert;
35 const static constexpr size_t smiPollingTimeMs = 1000;
36 const static constexpr size_t smiTimeoutMs = 90000;
37
38 void logEvent() override
39 {
40 sd_journal_send("MESSAGE=HostError: SMI Timeout", "PRIORITY=%i",
41 LOG_INFO, "REDFISH_MESSAGE_ID=%s",
42 "OpenBMC.0.1.CPUError", "REDFISH_MESSAGE_ARGS=%s",
43 "SMI Timeout", NULL);
44 }
45
46 void assertHandler() override
47 {
48 BaseGPIOPollMonitor::assertHandler();
49
50 conn->async_method_call(
51 [this](boost::system::error_code ec,
52 const std::variant<bool>& property) {
53 if (ec)
54 {
55 return;
56 }
57 const bool* reset = std::get_if<bool>(&property);
58 if (reset == nullptr)
59 {
60 std::cerr << "Unable to read reset on " << signalName
61 << " value\n";
62 return;
63 }
64#ifdef HOST_ERROR_CRASHDUMP_ON_SMI_TIMEOUT
65 startCrashdumpAndRecovery(conn, *reset, "SMI Timeout");
66#else
67 if (*reset)
68 {
69 std::cout << "Recovering the system\n";
70 startWarmReset(conn);
71 }
72#endif
73 },
74 "xyz.openbmc_project.Settings",
75 "/xyz/openbmc_project/control/bmc_reset_disables",
76 "org.freedesktop.DBus.Properties", "Get",
77 "xyz.openbmc_project.Control.ResetDisables", "ResetOnSMI");
78 }
79
80 public:
81 SMIMonitor(boost::asio::io_service& io,
82 std::shared_ptr<sdbusplus::asio::connection> conn,
83 const std::string& signalName) :
84 BaseGPIOPollMonitor(io, conn, signalName, assertValue, smiPollingTimeMs,
85 smiTimeoutMs)
86
87 {
88 if (valid)
89 {
90 startPolling();
91 }
92 }
93};
94} // namespace host_error_monitor::smi_monitor