blob: 6e22f768de70a5f336416b0af7474ff627c3bbe5 [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"
Ed Tanous18b61862025-01-30 10:56:28 -08005#include "Utils.hpp"
Andrew Jefferye73bd0a2023-01-25 10:39:57 +10306#include "sensor.hpp"
7
Ed Tanous18b61862025-01-30 10:56:28 -08008#include <boost/asio/io_context.hpp>
Josh Lehan5170fe62022-08-03 13:17:41 -07009#include <boost/asio/random_access_file.hpp>
Ed Tanous18b61862025-01-30 10:56:28 -080010#include <boost/asio/steady_timer.hpp>
James Feistdc6c55f2018-10-31 12:53:20 -070011#include <boost/container/flat_map.hpp>
Patrick Williams0c42f402021-08-27 16:05:45 -050012#include <phosphor-logging/lg2.hpp>
Ed Tanous18b61862025-01-30 10:56:28 -080013#include <sdbusplus/asio/connection.hpp>
James Feist38fb5982020-05-28 10:09:54 -070014#include <sdbusplus/asio/object_server.hpp>
15
Ed Tanous18b61862025-01-30 10:56:28 -080016#include <array>
17#include <cstddef>
Patrick Venturefd6ba732019-10-31 14:27:39 -070018#include <memory>
19#include <optional>
Patrick Venturefd6ba732019-10-31 14:27:39 -070020#include <string>
21#include <utility>
22#include <vector>
James Feist6714a252018-09-10 15:26:18 -070023
James Feist7b18b1e2019-05-14 13:42:09 -070024namespace redundancy
25{
26constexpr const char* full = "Full";
27constexpr const char* degraded = "Degraded";
28constexpr const char* failed = "Failed";
29} // namespace redundancy
30
James Feistdc6c55f2018-10-31 12:53:20 -070031class RedundancySensor
32{
33 public:
James Feistd8705872019-02-08 13:26:09 -080034 RedundancySensor(size_t count, const std::vector<std::string>& children,
James Feist9bb67462019-03-15 15:09:50 -070035 sdbusplus::asio::object_server& objectServer,
36 const std::string& sensorConfiguration);
James Feistdc6c55f2018-10-31 12:53:20 -070037 ~RedundancySensor();
38
James Feistd8705872019-02-08 13:26:09 -080039 void update(const std::string& name, bool failed);
James Feistdc6c55f2018-10-31 12:53:20 -070040
41 private:
42 size_t count;
James Feist7b18b1e2019-05-14 13:42:09 -070043 std::string state = redundancy::full;
James Feistdc6c55f2018-10-31 12:53:20 -070044 std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
James Feist9bb67462019-03-15 15:09:50 -070045 std::shared_ptr<sdbusplus::asio::dbus_interface> association;
James Feistd8705872019-02-08 13:26:09 -080046 sdbusplus::asio::object_server& objectServer;
James Feistdc6c55f2018-10-31 12:53:20 -070047 boost::container::flat_map<std::string, bool> statuses;
Chris Cain83929002024-03-06 14:20:09 -060048
49 static void logFanRedundancyLost()
50 {
51 const auto* msg = "OpenBMC.0.1.FanRedundancyLost";
52 lg2::error("Fan Inserted", "REDFISH_MESSAGE_ID", msg);
53 }
54
55 static void logFanRedundancyRestored()
56 {
57 const auto* msg = "OpenBMC.0.1.FanRedundancyRegained";
58 lg2::error("Fan Removed", "REDFISH_MESSAGE_ID", msg);
59 }
James Feistdc6c55f2018-10-31 12:53:20 -070060};
61
Josh Lehan5170fe62022-08-03 13:17:41 -070062class TachSensor :
63 public Sensor,
64 public std::enable_shared_from_this<TachSensor>
James Feist6714a252018-09-10 15:26:18 -070065{
66 public:
James Feistd8705872019-02-08 13:26:09 -080067 TachSensor(const std::string& path, const std::string& objectType,
68 sdbusplus::asio::object_server& objectServer,
69 std::shared_ptr<sdbusplus::asio::connection>& conn,
Chris Cain83929002024-03-06 14:20:09 -060070 std::shared_ptr<PresenceGpio>& presence,
James Feist7b18b1e2019-05-14 13:42:09 -070071 std::optional<RedundancySensor>* redundancy,
Ed Tanous1f978632023-02-28 18:16:39 -080072 boost::asio::io_context& io, const std::string& fanName,
James Feistd8705872019-02-08 13:26:09 -080073 std::vector<thresholds::Threshold>&& thresholds,
74 const std::string& sensorConfiguration,
Ed Tanousf69fbf92022-01-14 10:15:33 -080075 const std::pair<double, double>& limits,
James Feist49a8ccd2020-09-16 16:09:52 -070076 const PowerState& powerState,
77 const std::optional<std::string>& led);
Ed Tanous8a57ec02020-10-09 12:46:52 -070078 ~TachSensor() override;
Josh Lehan5170fe62022-08-03 13:17:41 -070079 void setupRead();
James Feist6714a252018-09-10 15:26:18 -070080
81 private:
Josh Lehan5170fe62022-08-03 13:17:41 -070082 // Ordering is important here; readBuf is first so that it's not destroyed
83 // while async operations from other member fields might still be using it.
84 std::array<char, 128> readBuf{};
James Feistd8705872019-02-08 13:26:09 -080085 sdbusplus::asio::object_server& objServer;
James Feist7b18b1e2019-05-14 13:42:09 -070086 std::optional<RedundancySensor>* redundancy;
Chris Cain83929002024-03-06 14:20:09 -060087 std::shared_ptr<PresenceGpio> presence;
James Feist60c0ec72019-03-18 15:08:43 -070088 std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface;
James Feistd8bd5622019-06-26 12:09:05 -070089 std::shared_ptr<sdbusplus::asio::dbus_interface> itemAssoc;
Josh Lehan5170fe62022-08-03 13:17:41 -070090 boost::asio::random_access_file inputDev;
Ed Tanous9b4a20e2022-09-06 08:47:11 -070091 boost::asio::steady_timer waitTimer;
James Feist930fcde2019-05-28 12:58:43 -070092 std::string path;
James Feist49a8ccd2020-09-16 16:09:52 -070093 std::optional<std::string> led;
94 bool ledState = false;
Josh Lehan5170fe62022-08-03 13:17:41 -070095
96 void handleResponse(const boost::system::error_code& err, size_t bytesRead);
97 void restartRead(size_t pollTime);
Ed Tanous201a1012024-04-03 18:07:28 -070098 void checkThresholds() override;
James Feist6714a252018-09-10 15:26:18 -070099};