James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | #pragma once |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 2 | |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 3 | #include "PresenceGpio.hpp" |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 4 | #include "Thresholds.hpp" |
| 5 | #include "sensor.hpp" |
| 6 | |
Josh Lehan | 5170fe6 | 2022-08-03 13:17:41 -0700 | [diff] [blame] | 7 | #include <boost/asio/random_access_file.hpp> |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 8 | #include <boost/container/flat_map.hpp> |
| 9 | #include <boost/container/flat_set.hpp> |
Zhikui Ren | 347dd4e | 2019-12-12 13:39:50 -0800 | [diff] [blame] | 10 | #include <gpiod.hpp> |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 11 | #include <phosphor-logging/lg2.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 12 | #include <sdbusplus/asio/object_server.hpp> |
| 13 | |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 14 | #include <memory> |
| 15 | #include <optional> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 16 | #include <string> |
| 17 | #include <utility> |
| 18 | #include <vector> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 19 | |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 20 | namespace redundancy |
| 21 | { |
| 22 | constexpr const char* full = "Full"; |
| 23 | constexpr const char* degraded = "Degraded"; |
| 24 | constexpr const char* failed = "Failed"; |
| 25 | } // namespace redundancy |
| 26 | |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 27 | class RedundancySensor |
| 28 | { |
| 29 | public: |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 30 | RedundancySensor(size_t count, const std::vector<std::string>& children, |
James Feist | 9bb6746 | 2019-03-15 15:09:50 -0700 | [diff] [blame] | 31 | sdbusplus::asio::object_server& objectServer, |
| 32 | const std::string& sensorConfiguration); |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 33 | ~RedundancySensor(); |
| 34 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 35 | void update(const std::string& name, bool failed); |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 36 | |
| 37 | private: |
| 38 | size_t count; |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 39 | std::string state = redundancy::full; |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 40 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface; |
James Feist | 9bb6746 | 2019-03-15 15:09:50 -0700 | [diff] [blame] | 41 | std::shared_ptr<sdbusplus::asio::dbus_interface> association; |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 42 | sdbusplus::asio::object_server& objectServer; |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 43 | boost::container::flat_map<std::string, bool> statuses; |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 44 | |
| 45 | static void logFanRedundancyLost() |
| 46 | { |
| 47 | const auto* msg = "OpenBMC.0.1.FanRedundancyLost"; |
| 48 | lg2::error("Fan Inserted", "REDFISH_MESSAGE_ID", msg); |
| 49 | } |
| 50 | |
| 51 | static void logFanRedundancyRestored() |
| 52 | { |
| 53 | const auto* msg = "OpenBMC.0.1.FanRedundancyRegained"; |
| 54 | lg2::error("Fan Removed", "REDFISH_MESSAGE_ID", msg); |
| 55 | } |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Josh Lehan | 5170fe6 | 2022-08-03 13:17:41 -0700 | [diff] [blame] | 58 | class TachSensor : |
| 59 | public Sensor, |
| 60 | public std::enable_shared_from_this<TachSensor> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 61 | { |
| 62 | public: |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 63 | TachSensor(const std::string& path, const std::string& objectType, |
| 64 | sdbusplus::asio::object_server& objectServer, |
| 65 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 66 | std::shared_ptr<PresenceGpio>& presence, |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 67 | std::optional<RedundancySensor>* redundancy, |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 68 | boost::asio::io_context& io, const std::string& fanName, |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 69 | std::vector<thresholds::Threshold>&& thresholds, |
| 70 | const std::string& sensorConfiguration, |
Ed Tanous | f69fbf9 | 2022-01-14 10:15:33 -0800 | [diff] [blame] | 71 | const std::pair<double, double>& limits, |
James Feist | 49a8ccd | 2020-09-16 16:09:52 -0700 | [diff] [blame] | 72 | const PowerState& powerState, |
| 73 | const std::optional<std::string>& led); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 74 | ~TachSensor() override; |
Josh Lehan | 5170fe6 | 2022-08-03 13:17:41 -0700 | [diff] [blame] | 75 | void setupRead(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 76 | |
| 77 | private: |
Josh Lehan | 5170fe6 | 2022-08-03 13:17:41 -0700 | [diff] [blame] | 78 | // Ordering is important here; readBuf is first so that it's not destroyed |
| 79 | // while async operations from other member fields might still be using it. |
| 80 | std::array<char, 128> readBuf{}; |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 81 | sdbusplus::asio::object_server& objServer; |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 82 | std::optional<RedundancySensor>* redundancy; |
Chris Cain | 8392900 | 2024-03-06 14:20:09 -0600 | [diff] [blame] | 83 | std::shared_ptr<PresenceGpio> presence; |
James Feist | 60c0ec7 | 2019-03-18 15:08:43 -0700 | [diff] [blame] | 84 | std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface; |
James Feist | d8bd562 | 2019-06-26 12:09:05 -0700 | [diff] [blame] | 85 | std::shared_ptr<sdbusplus::asio::dbus_interface> itemAssoc; |
Josh Lehan | 5170fe6 | 2022-08-03 13:17:41 -0700 | [diff] [blame] | 86 | boost::asio::random_access_file inputDev; |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 87 | boost::asio::steady_timer waitTimer; |
James Feist | 930fcde | 2019-05-28 12:58:43 -0700 | [diff] [blame] | 88 | std::string path; |
James Feist | 49a8ccd | 2020-09-16 16:09:52 -0700 | [diff] [blame] | 89 | std::optional<std::string> led; |
| 90 | bool ledState = false; |
Josh Lehan | 5170fe6 | 2022-08-03 13:17:41 -0700 | [diff] [blame] | 91 | |
| 92 | void handleResponse(const boost::system::error_code& err, size_t bytesRead); |
| 93 | void restartRead(size_t pollTime); |
Ed Tanous | 201a101 | 2024-04-03 18:07:28 -0700 | [diff] [blame] | 94 | void checkThresholds() override; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 95 | }; |