James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | #pragma once |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 2 | #include <Thresholds.hpp> |
James Feist | 8086aba | 2020-08-25 16:00:59 -0700 | [diff] [blame] | 3 | #include <boost/asio/streambuf.hpp> |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 4 | #include <boost/container/flat_map.hpp> |
| 5 | #include <boost/container/flat_set.hpp> |
Zhikui Ren | 347dd4e | 2019-12-12 13:39:50 -0800 | [diff] [blame] | 6 | #include <gpiod.hpp> |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 7 | #include <phosphor-logging/lg2.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 8 | #include <sdbusplus/asio/object_server.hpp> |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 9 | #include <sensor.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 10 | |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 11 | #include <memory> |
| 12 | #include <optional> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 13 | #include <string> |
| 14 | #include <utility> |
| 15 | #include <vector> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 16 | |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 17 | class PresenceSensor |
| 18 | { |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 19 | public: |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame^] | 20 | PresenceSensor(const std::string& gpioName, bool inverted, |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 21 | boost::asio::io_service& io, const std::string& name); |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 22 | ~PresenceSensor(); |
| 23 | |
| 24 | void monitorPresence(void); |
| 25 | void read(void); |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame^] | 26 | bool getValue(void) const; |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 27 | |
| 28 | private: |
| 29 | bool status = true; |
Zhikui Ren | 347dd4e | 2019-12-12 13:39:50 -0800 | [diff] [blame] | 30 | gpiod::line gpioLine; |
| 31 | boost::asio::posix::stream_descriptor gpioFd; |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 32 | std::string name; |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 33 | }; |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 34 | |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 35 | namespace redundancy |
| 36 | { |
| 37 | constexpr const char* full = "Full"; |
| 38 | constexpr const char* degraded = "Degraded"; |
| 39 | constexpr const char* failed = "Failed"; |
| 40 | } // namespace redundancy |
| 41 | |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 42 | class RedundancySensor |
| 43 | { |
| 44 | public: |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 45 | RedundancySensor(size_t count, const std::vector<std::string>& children, |
James Feist | 9bb6746 | 2019-03-15 15:09:50 -0700 | [diff] [blame] | 46 | sdbusplus::asio::object_server& objectServer, |
| 47 | const std::string& sensorConfiguration); |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 48 | ~RedundancySensor(); |
| 49 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 50 | void update(const std::string& name, bool failed); |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | size_t count; |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 54 | std::string state = redundancy::full; |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 55 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface; |
James Feist | 9bb6746 | 2019-03-15 15:09:50 -0700 | [diff] [blame] | 56 | std::shared_ptr<sdbusplus::asio::dbus_interface> association; |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 57 | sdbusplus::asio::object_server& objectServer; |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 58 | boost::container::flat_map<std::string, bool> statuses; |
| 59 | }; |
| 60 | |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 61 | class TachSensor : public Sensor |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 62 | { |
| 63 | public: |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 64 | TachSensor(const std::string& path, const std::string& objectType, |
| 65 | sdbusplus::asio::object_server& objectServer, |
| 66 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 67 | std::unique_ptr<PresenceSensor>&& presence, |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 68 | std::optional<RedundancySensor>* redundancy, |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 69 | boost::asio::io_service& io, const std::string& fanName, |
| 70 | std::vector<thresholds::Threshold>&& thresholds, |
| 71 | const std::string& sensorConfiguration, |
Ed Tanous | f69fbf9 | 2022-01-14 10:15:33 -0800 | [diff] [blame] | 72 | const std::pair<double, double>& limits, |
James Feist | 49a8ccd | 2020-09-16 16:09:52 -0700 | [diff] [blame] | 73 | const PowerState& powerState, |
| 74 | const std::optional<std::string>& led); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 75 | ~TachSensor() override; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 76 | |
| 77 | private: |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 78 | sdbusplus::asio::object_server& objServer; |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 79 | std::optional<RedundancySensor>* redundancy; |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 80 | std::unique_ptr<PresenceSensor> presence; |
James Feist | 60c0ec7 | 2019-03-18 15:08:43 -0700 | [diff] [blame] | 81 | std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface; |
James Feist | d8bd562 | 2019-06-26 12:09:05 -0700 | [diff] [blame] | 82 | std::shared_ptr<sdbusplus::asio::dbus_interface> itemAssoc; |
Ed Tanous | 77518b2 | 2021-11-05 13:02:23 -0700 | [diff] [blame] | 83 | boost::asio::streambuf readBuf; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 84 | boost::asio::posix::stream_descriptor inputDev; |
| 85 | boost::asio::deadline_timer waitTimer; |
James Feist | 930fcde | 2019-05-28 12:58:43 -0700 | [diff] [blame] | 86 | std::string path; |
James Feist | 49a8ccd | 2020-09-16 16:09:52 -0700 | [diff] [blame] | 87 | std::optional<std::string> led; |
| 88 | bool ledState = false; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 89 | void setupRead(void); |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 90 | void handleResponse(const boost::system::error_code& err); |
James Feist | ce3fca4 | 2018-11-21 12:58:24 -0800 | [diff] [blame] | 91 | void checkThresholds(void) override; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 92 | }; |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 93 | |
| 94 | inline void logFanInserted(const std::string& device) |
| 95 | { |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame^] | 96 | const auto* msg = "OpenBMC.0.1.FanInserted"; |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 97 | lg2::error("Fan Inserted", "REDFISH_MESSAGE_ID", msg, |
| 98 | "REDFISH_MESSAGE_ARGS", device); |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | inline void logFanRemoved(const std::string& device) |
| 102 | { |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame^] | 103 | const auto* msg = "OpenBMC.0.1.FanRemoved"; |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 104 | lg2::error("Fan Removed", "REDFISH_MESSAGE_ID", msg, "REDFISH_MESSAGE_ARGS", |
| 105 | device); |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | inline void logFanRedundancyLost(void) |
| 109 | { |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame^] | 110 | const auto* msg = "OpenBMC.0.1.FanRedundancyLost"; |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 111 | lg2::error("Fan Inserted", "REDFISH_MESSAGE_ID", msg); |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | inline void logFanRedundancyRestored(void) |
| 115 | { |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame^] | 116 | const auto* msg = "OpenBMC.0.1.FanRedundancyRegained"; |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 117 | lg2::error("Fan Removed", "REDFISH_MESSAGE_ID", msg); |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 118 | } |