blob: 772fefd77051aa472775995a603cf4c4609064a5 [file] [log] [blame]
Jason M. Bills0e06b842020-10-02 16:30:06 -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 <bitset>
24
Jason M. Bills881a4e12022-03-14 13:40:01 -070025namespace host_error_monitor::err_pin_timeout_monitor
Jason M. Bills0e06b842020-10-02 16:30:06 -070026{
27static constexpr bool debug = false;
28
Jason M. Bills881a4e12022-03-14 13:40:01 -070029class ErrPinTimeoutMonitor :
Jason M. Bills0e06b842020-10-02 16:30:06 -070030 public host_error_monitor::base_gpio_poll_monitor::BaseGPIOPollMonitor
31{
32 size_t errPin;
33 std::bitset<MAX_CPUS> errPinCPUs;
34 const static host_error_monitor::base_gpio_poll_monitor::AssertValue
35 assertValue =
36 host_error_monitor::base_gpio_poll_monitor::AssertValue::lowAssert;
37 const static constexpr size_t errPinPollingTimeMs = 1000;
38 const static constexpr size_t errPinTimeoutMs = 90000;
39
40 void logEvent()
41 {
42 if (errPinCPUs.none())
43 {
44 return errPinTimeoutLog();
45 }
46
47 for (size_t i = 0; i < errPinCPUs.size(); i++)
48 {
49 if (errPinCPUs[i])
50 {
51 errPinTimeoutLog(i);
52 }
53 }
54 }
55
56 void errPinTimeoutLog()
57 {
58 std::string msg = "ERR" + std::to_string(errPin) + " Timeout";
59
60 sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i",
61 LOG_INFO, "REDFISH_MESSAGE_ID=%s",
62 "OpenBMC.0.1.CPUError", "REDFISH_MESSAGE_ARGS=%s",
63 msg.c_str(), NULL);
64 }
65
66 void errPinTimeoutLog(const int cpuNum)
67 {
68 std::string msg = "ERR" + std::to_string(errPin) + " Timeout on CPU " +
69 std::to_string(cpuNum + 1);
70
71 sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i",
72 LOG_INFO, "REDFISH_MESSAGE_ID=%s",
73 "OpenBMC.0.1.CPUError", "REDFISH_MESSAGE_ARGS=%s",
74 msg.c_str(), NULL);
75 }
76
Jason M. Bills0e06b842020-10-02 16:30:06 -070077 void startPolling() override
78 {
Jason M. Bills32a90c62022-03-14 13:33:31 -070079 checkErrPinCPUs(errPin, errPinCPUs);
Jason M. Bills0e06b842020-10-02 16:30:06 -070080 host_error_monitor::base_gpio_poll_monitor::BaseGPIOPollMonitor::
81 startPolling();
82 }
83
84 public:
Jason M. Bills881a4e12022-03-14 13:40:01 -070085 ErrPinTimeoutMonitor(boost::asio::io_service& io,
86 std::shared_ptr<sdbusplus::asio::connection> conn,
87 const std::string& signalName, const size_t errPin) :
Jason M. Bills0e06b842020-10-02 16:30:06 -070088 BaseGPIOPollMonitor(io, conn, signalName, assertValue,
89 errPinPollingTimeMs, errPinTimeoutMs),
90 errPin(errPin)
91 {
92 if (valid)
93 {
94 startPolling();
95 }
96 }
97};
Jason M. Bills881a4e12022-03-14 13:40:01 -070098} // namespace host_error_monitor::err_pin_timeout_monitor