James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 1 | #pragma once |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 2 | #include <boost/asio/deadline_timer.hpp> |
| 3 | #include <boost/container/flat_map.hpp> |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 4 | #include <sensor.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 5 | |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 6 | #include <chrono> |
| 7 | #include <limits> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 8 | #include <memory> |
| 9 | #include <optional> |
| 10 | #include <string> |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
| 13 | enum class IpmbType |
| 14 | { |
| 15 | meSensor, |
| 16 | PXE1410CVR, |
| 17 | IR38363VR, |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 18 | ADM1278HSC, |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 19 | mpsVR |
| 20 | }; |
| 21 | |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 22 | enum class IpmbSubType |
| 23 | { |
| 24 | temp, |
| 25 | curr, |
| 26 | power, |
Adrian Ambrożewicz | 45e9277 | 2020-06-04 13:59:55 +0200 | [diff] [blame] | 27 | volt, |
| 28 | util |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 31 | enum class ReadingFormat |
| 32 | { |
| 33 | byte0, |
| 34 | byte3, |
| 35 | elevenBit, |
| 36 | elevenBitShift, |
Jayashree-D | 3732257 | 2021-03-19 17:40:56 +0530 | [diff] [blame] | 37 | linearElevenBit |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
Adrian Ambrożewicz | 58e02ef | 2020-08-06 14:42:38 +0200 | [diff] [blame] | 40 | namespace ipmi |
| 41 | { |
| 42 | namespace sensor |
| 43 | { |
| 44 | constexpr uint8_t netFn = 0x04; |
| 45 | constexpr uint8_t getSensorReading = 0x2d; |
| 46 | |
| 47 | static bool isValid(const std::vector<uint8_t>& data) |
| 48 | { |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 49 | constexpr auto readingUnavailableBit = 5; |
Adrian Ambrożewicz | 58e02ef | 2020-08-06 14:42:38 +0200 | [diff] [blame] | 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 |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 60 | if (data[1] & (1 << readingUnavailableBit)) |
Adrian Ambrożewicz | 58e02ef | 2020-08-06 14:42:38 +0200 | [diff] [blame] | 61 | { |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | } // namespace sensor |
| 69 | namespace me_bridge |
| 70 | { |
| 71 | constexpr uint8_t netFn = 0x2e; |
| 72 | constexpr uint8_t sendRawPmbus = 0xd9; |
| 73 | } // namespace me_bridge |
| 74 | } // namespace ipmi |
| 75 | |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 76 | struct IpmbSensor : public Sensor |
| 77 | { |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 78 | 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 S | 832a2c6 | 2020-11-20 19:21:22 +0000 | [diff] [blame] | 83 | uint8_t deviceAddress, uint8_t hostSMbusIndex, |
Jayashree-D | 9f6d4fd | 2021-04-13 18:27:22 +0530 | [diff] [blame^] | 84 | const float pollRate, std::string& sensorTypeName); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 85 | ~IpmbSensor() override; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 86 | |
| 87 | void checkThresholds(void) override; |
| 88 | void read(void); |
| 89 | void init(void); |
Zev Weiss | 6b6891c | 2021-04-22 02:46:21 -0500 | [diff] [blame] | 90 | std::string getSubTypeUnits(void); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 91 | void loadDefaults(void); |
James Feist | f7e2c5d | 2019-02-13 17:27:51 -0800 | [diff] [blame] | 92 | void runInitCmd(void); |
James Feist | 961bf09 | 2020-07-01 16:38:12 -0700 | [diff] [blame] | 93 | bool processReading(const std::vector<uint8_t>& data, double& resp); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 94 | |
| 95 | IpmbType type; |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 96 | IpmbSubType subType; |
| 97 | double scaleVal; |
| 98 | double offsetVal; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 99 | uint8_t commandAddress; |
| 100 | uint8_t netfn; |
| 101 | uint8_t command; |
| 102 | uint8_t deviceAddress; |
James Feist | 551087a | 2019-12-09 11:17:12 -0800 | [diff] [blame] | 103 | uint8_t errorCount; |
Anoop S | 832a2c6 | 2020-11-20 19:21:22 +0000 | [diff] [blame] | 104 | uint8_t hostSMbusIndex; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 105 | std::vector<uint8_t> commandData; |
| 106 | std::optional<uint8_t> initCommand; |
| 107 | std::vector<uint8_t> initData; |
Jayashree-D | 9f6d4fd | 2021-04-13 18:27:22 +0530 | [diff] [blame^] | 108 | int sensorPollMs; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 109 | |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 110 | ReadingFormat readingFormat; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 111 | |
| 112 | private: |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 113 | sdbusplus::asio::object_server& objectServer; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 114 | boost::asio::deadline_timer waitTimer; |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 115 | }; |