blob: f142a5aa13cfcb6b28a81dbff45f8ab077e25c7a [file] [log] [blame]
James Feist6ef20402019-01-07 16:45:08 -08001#pragma once
Ed Tanous9b4a20e2022-09-06 08:47:11 -07002#include <boost/asio/steady_timer.hpp>
James Feist6ef20402019-01-07 16:45:08 -08003#include <boost/container/flat_map.hpp>
Ed Tanous8a57ec02020-10-09 12:46:52 -07004#include <sensor.hpp>
James Feist38fb5982020-05-28 10:09:54 -07005
James Feist6ef20402019-01-07 16:45:08 -08006#include <chrono>
7#include <limits>
Patrick Venturefd6ba732019-10-31 14:27:39 -07008#include <memory>
9#include <optional>
10#include <string>
James Feist6ef20402019-01-07 16:45:08 -080011#include <vector>
12
13enum class IpmbType
14{
Ed Tanousa771f6a2022-01-14 09:36:51 -080015 none,
James Feist6ef20402019-01-07 16:45:08 -080016 meSensor,
17 PXE1410CVR,
18 IR38363VR,
Vijay Khemka682a5cb2019-07-18 17:34:03 -070019 ADM1278HSC,
James Feist6ef20402019-01-07 16:45:08 -080020 mpsVR
21};
22
Vijay Khemka682a5cb2019-07-18 17:34:03 -070023enum class IpmbSubType
24{
Ed Tanousa771f6a2022-01-14 09:36:51 -080025 none,
Vijay Khemka682a5cb2019-07-18 17:34:03 -070026 temp,
27 curr,
28 power,
Adrian Ambrożewicz45e92772020-06-04 13:59:55 +020029 volt,
30 util
Vijay Khemka682a5cb2019-07-18 17:34:03 -070031};
32
James Feistd7ae29a2020-06-25 15:42:46 -070033enum class ReadingFormat
34{
35 byte0,
36 byte3,
37 elevenBit,
38 elevenBitShift,
Jayashree-D37322572021-03-19 17:40:56 +053039 linearElevenBit
James Feistd7ae29a2020-06-25 15:42:46 -070040};
41
Adrian Ambrożewicz58e02ef2020-08-06 14:42:38 +020042namespace ipmi
43{
44namespace sensor
45{
46constexpr uint8_t netFn = 0x04;
47constexpr uint8_t getSensorReading = 0x2d;
48
49static bool isValid(const std::vector<uint8_t>& data)
50{
Ed Tanous8a57ec02020-10-09 12:46:52 -070051 constexpr auto readingUnavailableBit = 5;
Adrian Ambrożewicz58e02ef2020-08-06 14:42:38 +020052
53 // Proper 'Get Sensor Reading' response has at least 4 bytes, including
54 // Completion Code. Our IPMB stack strips Completion Code from payload so we
55 // compare here against the rest of payload
56 if (data.size() < 3)
57 {
58 return false;
59 }
60
61 // Per IPMI 'Get Sensor Reading' specification
Ed Tanous2049bd22022-07-09 07:20:26 -070062 if ((data[1] & (1 << readingUnavailableBit)) != 0)
Adrian Ambrożewicz58e02ef2020-08-06 14:42:38 +020063 {
64 return false;
65 }
66
67 return true;
68}
69
70} // namespace sensor
71namespace me_bridge
72{
73constexpr uint8_t netFn = 0x2e;
74constexpr uint8_t sendRawPmbus = 0xd9;
75} // namespace me_bridge
76} // namespace ipmi
77
James Feist6ef20402019-01-07 16:45:08 -080078struct IpmbSensor : public Sensor
79{
James Feistd8705872019-02-08 13:26:09 -080080 IpmbSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
81 boost::asio::io_service& io, const std::string& name,
82 const std::string& sensorConfiguration,
83 sdbusplus::asio::object_server& objectServer,
Ed Tanous2049bd22022-07-09 07:20:26 -070084 std::vector<thresholds::Threshold>&& thresholdData,
85 uint8_t deviceAddress, uint8_t hostSMbusIndex, float pollRate,
86 std::string& sensorTypeName);
Ed Tanous8a57ec02020-10-09 12:46:52 -070087 ~IpmbSensor() override;
James Feist6ef20402019-01-07 16:45:08 -080088
89 void checkThresholds(void) override;
90 void read(void);
91 void init(void);
Ed Tanous2049bd22022-07-09 07:20:26 -070092 std::string getSubTypeUnits(void) const;
James Feist6ef20402019-01-07 16:45:08 -080093 void loadDefaults(void);
James Feistf7e2c5d2019-02-13 17:27:51 -080094 void runInitCmd(void);
James Feist961bf092020-07-01 16:38:12 -070095 bool processReading(const std::vector<uint8_t>& data, double& resp);
Jayashree Dhanapal84189752022-03-07 12:51:54 +053096 void parseConfigValues(const SensorBaseConfigMap& entry);
97 bool sensorClassType(const std::string& sensorClass);
98 void sensorSubType(const std::string& sensorTypeName);
James Feist6ef20402019-01-07 16:45:08 -080099
Ed Tanousa771f6a2022-01-14 09:36:51 -0800100 IpmbType type = IpmbType::none;
101 IpmbSubType subType = IpmbSubType::none;
102 double scaleVal = 1.0;
103 double offsetVal = 0.0;
104 uint8_t commandAddress = 0;
105 uint8_t netfn = 0;
106 uint8_t command = 0;
107 uint8_t deviceAddress = 0;
108 uint8_t errorCount = 0;
109 uint8_t hostSMbusIndex = 0;
James Feist6ef20402019-01-07 16:45:08 -0800110 std::vector<uint8_t> commandData;
111 std::optional<uint8_t> initCommand;
112 std::vector<uint8_t> initData;
Jayashree-D9f6d4fd2021-04-13 18:27:22 +0530113 int sensorPollMs;
James Feist6ef20402019-01-07 16:45:08 -0800114
Ed Tanousa771f6a2022-01-14 09:36:51 -0800115 ReadingFormat readingFormat = ReadingFormat::byte0;
James Feist6ef20402019-01-07 16:45:08 -0800116
117 private:
James Feistd8705872019-02-08 13:26:09 -0800118 sdbusplus::asio::object_server& objectServer;
Ed Tanous9b4a20e2022-09-06 08:47:11 -0700119 boost::asio::steady_timer waitTimer;
Vijay Khemka682a5cb2019-07-18 17:34:03 -0700120};