Jason M. Bills | 0e06b84 | 2020-10-02 16:30:06 -0700 | [diff] [blame] | 1 | /* |
| 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. Bills | 881a4e1 | 2022-03-14 13:40:01 -0700 | [diff] [blame] | 25 | namespace host_error_monitor::err_pin_timeout_monitor |
Jason M. Bills | 0e06b84 | 2020-10-02 16:30:06 -0700 | [diff] [blame] | 26 | { |
| 27 | static constexpr bool debug = false; |
| 28 | |
Jason M. Bills | 881a4e1 | 2022-03-14 13:40:01 -0700 | [diff] [blame] | 29 | class ErrPinTimeoutMonitor : |
Jason M. Bills | 0e06b84 | 2020-10-02 16:30:06 -0700 | [diff] [blame] | 30 | 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. Bills | 0e06b84 | 2020-10-02 16:30:06 -0700 | [diff] [blame] | 77 | void startPolling() override |
| 78 | { |
Jason M. Bills | 32a90c6 | 2022-03-14 13:33:31 -0700 | [diff] [blame] | 79 | checkErrPinCPUs(errPin, errPinCPUs); |
Jason M. Bills | 0e06b84 | 2020-10-02 16:30:06 -0700 | [diff] [blame] | 80 | host_error_monitor::base_gpio_poll_monitor::BaseGPIOPollMonitor:: |
| 81 | startPolling(); |
| 82 | } |
| 83 | |
| 84 | public: |
Ed Tanous | ee00ccc | 2023-03-01 10:37:43 -0800 | [diff] [blame] | 85 | ErrPinTimeoutMonitor(boost::asio::io_context& io, |
Jason M. Bills | 881a4e1 | 2022-03-14 13:40:01 -0700 | [diff] [blame] | 86 | std::shared_ptr<sdbusplus::asio::connection> conn, |
| 87 | const std::string& signalName, const size_t errPin) : |
Jason M. Bills | 0e06b84 | 2020-10-02 16:30:06 -0700 | [diff] [blame] | 88 | BaseGPIOPollMonitor(io, conn, signalName, assertValue, |
| 89 | errPinPollingTimeMs, errPinTimeoutMs), |
| 90 | errPin(errPin) |
| 91 | { |
| 92 | if (valid) |
| 93 | { |
| 94 | startPolling(); |
| 95 | } |
| 96 | } |
| 97 | }; |
Jason M. Bills | 881a4e1 | 2022-03-14 13:40:01 -0700 | [diff] [blame] | 98 | } // namespace host_error_monitor::err_pin_timeout_monitor |