blob: d2ca101cd03ecf6916194dded9f0527e9834a3f4 [file] [log] [blame]
James Feist6714a252018-09-10 15:26:18 -07001#pragma once
Andrew Jefferye73bd0a2023-01-25 10:39:57 +10302
Chris Cain83929002024-03-06 14:20:09 -06003#include "PresenceGpio.hpp"
Andrew Jefferye73bd0a2023-01-25 10:39:57 +10304#include "Thresholds.hpp"
5#include "sensor.hpp"
6
Josh Lehan5170fe62022-08-03 13:17:41 -07007#include <boost/asio/random_access_file.hpp>
James Feistdc6c55f2018-10-31 12:53:20 -07008#include <boost/container/flat_map.hpp>
9#include <boost/container/flat_set.hpp>
Zhikui Ren347dd4e2019-12-12 13:39:50 -080010#include <gpiod.hpp>
Patrick Williams0c42f402021-08-27 16:05:45 -050011#include <phosphor-logging/lg2.hpp>
James Feist38fb5982020-05-28 10:09:54 -070012#include <sdbusplus/asio/object_server.hpp>
13
Patrick Venturefd6ba732019-10-31 14:27:39 -070014#include <memory>
15#include <optional>
Patrick Venturefd6ba732019-10-31 14:27:39 -070016#include <string>
17#include <utility>
18#include <vector>
James Feist6714a252018-09-10 15:26:18 -070019
James Feist7b18b1e2019-05-14 13:42:09 -070020namespace redundancy
21{
22constexpr const char* full = "Full";
23constexpr const char* degraded = "Degraded";
24constexpr const char* failed = "Failed";
25} // namespace redundancy
26
James Feistdc6c55f2018-10-31 12:53:20 -070027class RedundancySensor
28{
29 public:
James Feistd8705872019-02-08 13:26:09 -080030 RedundancySensor(size_t count, const std::vector<std::string>& children,
James Feist9bb67462019-03-15 15:09:50 -070031 sdbusplus::asio::object_server& objectServer,
32 const std::string& sensorConfiguration);
James Feistdc6c55f2018-10-31 12:53:20 -070033 ~RedundancySensor();
34
James Feistd8705872019-02-08 13:26:09 -080035 void update(const std::string& name, bool failed);
James Feistdc6c55f2018-10-31 12:53:20 -070036
37 private:
38 size_t count;
James Feist7b18b1e2019-05-14 13:42:09 -070039 std::string state = redundancy::full;
James Feistdc6c55f2018-10-31 12:53:20 -070040 std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
James Feist9bb67462019-03-15 15:09:50 -070041 std::shared_ptr<sdbusplus::asio::dbus_interface> association;
James Feistd8705872019-02-08 13:26:09 -080042 sdbusplus::asio::object_server& objectServer;
James Feistdc6c55f2018-10-31 12:53:20 -070043 boost::container::flat_map<std::string, bool> statuses;
Chris Cain83929002024-03-06 14:20:09 -060044
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 Feistdc6c55f2018-10-31 12:53:20 -070056};
57
Josh Lehan5170fe62022-08-03 13:17:41 -070058class TachSensor :
59 public Sensor,
60 public std::enable_shared_from_this<TachSensor>
James Feist6714a252018-09-10 15:26:18 -070061{
62 public:
James Feistd8705872019-02-08 13:26:09 -080063 TachSensor(const std::string& path, const std::string& objectType,
64 sdbusplus::asio::object_server& objectServer,
65 std::shared_ptr<sdbusplus::asio::connection>& conn,
Chris Cain83929002024-03-06 14:20:09 -060066 std::shared_ptr<PresenceGpio>& presence,
James Feist7b18b1e2019-05-14 13:42:09 -070067 std::optional<RedundancySensor>* redundancy,
Ed Tanous1f978632023-02-28 18:16:39 -080068 boost::asio::io_context& io, const std::string& fanName,
James Feistd8705872019-02-08 13:26:09 -080069 std::vector<thresholds::Threshold>&& thresholds,
70 const std::string& sensorConfiguration,
Ed Tanousf69fbf92022-01-14 10:15:33 -080071 const std::pair<double, double>& limits,
James Feist49a8ccd2020-09-16 16:09:52 -070072 const PowerState& powerState,
73 const std::optional<std::string>& led);
Ed Tanous8a57ec02020-10-09 12:46:52 -070074 ~TachSensor() override;
Josh Lehan5170fe62022-08-03 13:17:41 -070075 void setupRead();
James Feist6714a252018-09-10 15:26:18 -070076
77 private:
Josh Lehan5170fe62022-08-03 13:17:41 -070078 // 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 Feistd8705872019-02-08 13:26:09 -080081 sdbusplus::asio::object_server& objServer;
James Feist7b18b1e2019-05-14 13:42:09 -070082 std::optional<RedundancySensor>* redundancy;
Chris Cain83929002024-03-06 14:20:09 -060083 std::shared_ptr<PresenceGpio> presence;
James Feist60c0ec72019-03-18 15:08:43 -070084 std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface;
James Feistd8bd5622019-06-26 12:09:05 -070085 std::shared_ptr<sdbusplus::asio::dbus_interface> itemAssoc;
Josh Lehan5170fe62022-08-03 13:17:41 -070086 boost::asio::random_access_file inputDev;
Ed Tanous9b4a20e2022-09-06 08:47:11 -070087 boost::asio::steady_timer waitTimer;
James Feist930fcde2019-05-28 12:58:43 -070088 std::string path;
James Feist49a8ccd2020-09-16 16:09:52 -070089 std::optional<std::string> led;
90 bool ledState = false;
Josh Lehan5170fe62022-08-03 13:17:41 -070091
92 void handleResponse(const boost::system::error_code& err, size_t bytesRead);
93 void restartRead(size_t pollTime);
Ed Tanous201a1012024-04-03 18:07:28 -070094 void checkThresholds() override;
James Feist6714a252018-09-10 15:26:18 -070095};