blob: 4207d1c603743edaf3cddb2b7da485a13d5fee64 [file] [log] [blame]
James Feist6ef20402019-01-07 16:45:08 -08001#pragma once
2#include "sensor.hpp"
3
4#include <boost/asio/deadline_timer.hpp>
5#include <boost/container/flat_map.hpp>
James Feist38fb5982020-05-28 10:09:54 -07006
James Feist6ef20402019-01-07 16:45:08 -08007#include <chrono>
8#include <limits>
Patrick Venturefd6ba732019-10-31 14:27:39 -07009#include <memory>
10#include <optional>
11#include <string>
James Feist6ef20402019-01-07 16:45:08 -080012#include <vector>
13
14enum class IpmbType
15{
16 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{
25 temp,
26 curr,
27 power,
Adrian Ambrożewicz45e92772020-06-04 13:59:55 +020028 volt,
29 util
Vijay Khemka682a5cb2019-07-18 17:34:03 -070030};
31
James Feistd7ae29a2020-06-25 15:42:46 -070032enum class ReadingFormat
33{
34 byte0,
35 byte3,
36 elevenBit,
37 elevenBitShift,
38};
39
Adrian Ambrożewicz58e02ef2020-08-06 14:42:38 +020040namespace ipmi
41{
42namespace sensor
43{
44constexpr uint8_t netFn = 0x04;
45constexpr uint8_t getSensorReading = 0x2d;
46
47static bool isValid(const std::vector<uint8_t>& data)
48{
49 constexpr auto ReadingUnavailableBit = 5;
50
51 // Proper 'Get Sensor Reading' response has at least 4 bytes, including
52 // Completion Code. Our IPMB stack strips Completion Code from payload so we
53 // compare here against the rest of payload
54 if (data.size() < 3)
55 {
56 return false;
57 }
58
59 // Per IPMI 'Get Sensor Reading' specification
60 if (data[1] & (1 << ReadingUnavailableBit))
61 {
62 return false;
63 }
64
65 return true;
66}
67
68} // namespace sensor
69namespace me_bridge
70{
71constexpr uint8_t netFn = 0x2e;
72constexpr uint8_t sendRawPmbus = 0xd9;
73} // namespace me_bridge
74} // namespace ipmi
75
James Feist6ef20402019-01-07 16:45:08 -080076struct IpmbSensor : public Sensor
77{
James Feistd8705872019-02-08 13:26:09 -080078 IpmbSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
79 boost::asio::io_service& io, const std::string& name,
80 const std::string& sensorConfiguration,
81 sdbusplus::asio::object_server& objectServer,
82 std::vector<thresholds::Threshold>&& thresholds,
Anoop S832a2c62020-11-20 19:21:22 +000083 uint8_t deviceAddress, uint8_t hostSMbusIndex,
84 std::string& sensorTypeName);
James Feist6ef20402019-01-07 16:45:08 -080085 ~IpmbSensor();
86
87 void checkThresholds(void) override;
88 void read(void);
89 void init(void);
90 void loadDefaults(void);
James Feistf7e2c5d2019-02-13 17:27:51 -080091 void runInitCmd(void);
James Feist961bf092020-07-01 16:38:12 -070092 bool processReading(const std::vector<uint8_t>& data, double& resp);
James Feist6ef20402019-01-07 16:45:08 -080093
94 IpmbType type;
Vijay Khemka682a5cb2019-07-18 17:34:03 -070095 IpmbSubType subType;
96 double scaleVal;
97 double offsetVal;
James Feist6ef20402019-01-07 16:45:08 -080098 uint8_t commandAddress;
99 uint8_t netfn;
100 uint8_t command;
101 uint8_t deviceAddress;
James Feist551087a2019-12-09 11:17:12 -0800102 uint8_t errorCount;
Anoop S832a2c62020-11-20 19:21:22 +0000103 uint8_t hostSMbusIndex;
James Feist6ef20402019-01-07 16:45:08 -0800104 std::vector<uint8_t> commandData;
105 std::optional<uint8_t> initCommand;
106 std::vector<uint8_t> initData;
107
James Feistd7ae29a2020-06-25 15:42:46 -0700108 ReadingFormat readingFormat;
James Feist6ef20402019-01-07 16:45:08 -0800109
110 private:
James Feistd8705872019-02-08 13:26:09 -0800111 sdbusplus::asio::object_server& objectServer;
James Feist6ef20402019-01-07 16:45:08 -0800112 boost::asio::deadline_timer waitTimer;
Vijay Khemka682a5cb2019-07-18 17:34:03 -0700113};