blob: 1d124b1a0e5578cc143f2a7a644b1314965f3cc5 [file] [log] [blame]
James Feist6ef20402019-01-07 16:45:08 -08001#pragma once
James Feist6ef20402019-01-07 16:45:08 -08002#include <boost/asio/deadline_timer.hpp>
3#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{
15 meSensor,
16 PXE1410CVR,
17 IR38363VR,
Vijay Khemka682a5cb2019-07-18 17:34:03 -070018 ADM1278HSC,
James Feist6ef20402019-01-07 16:45:08 -080019 mpsVR
20};
21
Vijay Khemka682a5cb2019-07-18 17:34:03 -070022enum class IpmbSubType
23{
24 temp,
25 curr,
26 power,
Adrian Ambrożewicz45e92772020-06-04 13:59:55 +020027 volt,
28 util
Vijay Khemka682a5cb2019-07-18 17:34:03 -070029};
30
James Feistd7ae29a2020-06-25 15:42:46 -070031enum class ReadingFormat
32{
33 byte0,
34 byte3,
35 elevenBit,
36 elevenBitShift,
37};
38
Adrian Ambrożewicz58e02ef2020-08-06 14:42:38 +020039namespace ipmi
40{
41namespace sensor
42{
43constexpr uint8_t netFn = 0x04;
44constexpr uint8_t getSensorReading = 0x2d;
45
46static bool isValid(const std::vector<uint8_t>& data)
47{
Ed Tanous8a57ec02020-10-09 12:46:52 -070048 constexpr auto readingUnavailableBit = 5;
Adrian Ambrożewicz58e02ef2020-08-06 14:42:38 +020049
50 // Proper 'Get Sensor Reading' response has at least 4 bytes, including
51 // Completion Code. Our IPMB stack strips Completion Code from payload so we
52 // compare here against the rest of payload
53 if (data.size() < 3)
54 {
55 return false;
56 }
57
58 // Per IPMI 'Get Sensor Reading' specification
Ed Tanous8a57ec02020-10-09 12:46:52 -070059 if (data[1] & (1 << readingUnavailableBit))
Adrian Ambrożewicz58e02ef2020-08-06 14:42:38 +020060 {
61 return false;
62 }
63
64 return true;
65}
66
67} // namespace sensor
68namespace me_bridge
69{
70constexpr uint8_t netFn = 0x2e;
71constexpr uint8_t sendRawPmbus = 0xd9;
72} // namespace me_bridge
73} // namespace ipmi
74
James Feist6ef20402019-01-07 16:45:08 -080075struct IpmbSensor : public Sensor
76{
James Feistd8705872019-02-08 13:26:09 -080077 IpmbSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
78 boost::asio::io_service& io, const std::string& name,
79 const std::string& sensorConfiguration,
80 sdbusplus::asio::object_server& objectServer,
81 std::vector<thresholds::Threshold>&& thresholds,
Anoop S832a2c62020-11-20 19:21:22 +000082 uint8_t deviceAddress, uint8_t hostSMbusIndex,
83 std::string& sensorTypeName);
Ed Tanous8a57ec02020-10-09 12:46:52 -070084 ~IpmbSensor() override;
James Feist6ef20402019-01-07 16:45:08 -080085
86 void checkThresholds(void) override;
87 void read(void);
88 void init(void);
89 void loadDefaults(void);
James Feistf7e2c5d2019-02-13 17:27:51 -080090 void runInitCmd(void);
James Feist961bf092020-07-01 16:38:12 -070091 bool processReading(const std::vector<uint8_t>& data, double& resp);
James Feist6ef20402019-01-07 16:45:08 -080092
93 IpmbType type;
Vijay Khemka682a5cb2019-07-18 17:34:03 -070094 IpmbSubType subType;
95 double scaleVal;
96 double offsetVal;
James Feist6ef20402019-01-07 16:45:08 -080097 uint8_t commandAddress;
98 uint8_t netfn;
99 uint8_t command;
100 uint8_t deviceAddress;
James Feist551087a2019-12-09 11:17:12 -0800101 uint8_t errorCount;
Anoop S832a2c62020-11-20 19:21:22 +0000102 uint8_t hostSMbusIndex;
James Feist6ef20402019-01-07 16:45:08 -0800103 std::vector<uint8_t> commandData;
104 std::optional<uint8_t> initCommand;
105 std::vector<uint8_t> initData;
106
James Feistd7ae29a2020-06-25 15:42:46 -0700107 ReadingFormat readingFormat;
James Feist6ef20402019-01-07 16:45:08 -0800108
109 private:
James Feistd8705872019-02-08 13:26:09 -0800110 sdbusplus::asio::object_server& objectServer;
James Feist6ef20402019-01-07 16:45:08 -0800111 boost::asio::deadline_timer waitTimer;
Vijay Khemka682a5cb2019-07-18 17:34:03 -0700112};