James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 1 | #pragma once |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame^] | 2 | #include <boost/asio/steady_timer.hpp> |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 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 | { |
Ed Tanous | a771f6a | 2022-01-14 09:36:51 -0800 | [diff] [blame] | 15 | none, |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 16 | meSensor, |
| 17 | PXE1410CVR, |
| 18 | IR38363VR, |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 19 | ADM1278HSC, |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 20 | mpsVR |
| 21 | }; |
| 22 | |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 23 | enum class IpmbSubType |
| 24 | { |
Ed Tanous | a771f6a | 2022-01-14 09:36:51 -0800 | [diff] [blame] | 25 | none, |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 26 | temp, |
| 27 | curr, |
| 28 | power, |
Adrian Ambrożewicz | 45e9277 | 2020-06-04 13:59:55 +0200 | [diff] [blame] | 29 | volt, |
| 30 | util |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 31 | }; |
| 32 | |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 33 | enum class ReadingFormat |
| 34 | { |
| 35 | byte0, |
| 36 | byte3, |
| 37 | elevenBit, |
| 38 | elevenBitShift, |
Jayashree-D | 3732257 | 2021-03-19 17:40:56 +0530 | [diff] [blame] | 39 | linearElevenBit |
James Feist | d7ae29a | 2020-06-25 15:42:46 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
Adrian Ambrożewicz | 58e02ef | 2020-08-06 14:42:38 +0200 | [diff] [blame] | 42 | namespace ipmi |
| 43 | { |
| 44 | namespace sensor |
| 45 | { |
| 46 | constexpr uint8_t netFn = 0x04; |
| 47 | constexpr uint8_t getSensorReading = 0x2d; |
| 48 | |
| 49 | static bool isValid(const std::vector<uint8_t>& data) |
| 50 | { |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 51 | constexpr auto readingUnavailableBit = 5; |
Adrian Ambrożewicz | 58e02ef | 2020-08-06 14:42:38 +0200 | [diff] [blame] | 52 | |
| 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 Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 62 | if ((data[1] & (1 << readingUnavailableBit)) != 0) |
Adrian Ambrożewicz | 58e02ef | 2020-08-06 14:42:38 +0200 | [diff] [blame] | 63 | { |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | } // namespace sensor |
| 71 | namespace me_bridge |
| 72 | { |
| 73 | constexpr uint8_t netFn = 0x2e; |
| 74 | constexpr uint8_t sendRawPmbus = 0xd9; |
| 75 | } // namespace me_bridge |
| 76 | } // namespace ipmi |
| 77 | |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 78 | struct IpmbSensor : public Sensor |
| 79 | { |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 80 | 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 Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 84 | std::vector<thresholds::Threshold>&& thresholdData, |
| 85 | uint8_t deviceAddress, uint8_t hostSMbusIndex, float pollRate, |
| 86 | std::string& sensorTypeName); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 87 | ~IpmbSensor() override; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 88 | |
| 89 | void checkThresholds(void) override; |
| 90 | void read(void); |
| 91 | void init(void); |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 92 | std::string getSubTypeUnits(void) const; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 93 | void loadDefaults(void); |
James Feist | f7e2c5d | 2019-02-13 17:27:51 -0800 | [diff] [blame] | 94 | void runInitCmd(void); |
James Feist | 961bf09 | 2020-07-01 16:38:12 -0700 | [diff] [blame] | 95 | bool processReading(const std::vector<uint8_t>& data, double& resp); |
Jayashree Dhanapal | 8418975 | 2022-03-07 12:51:54 +0530 | [diff] [blame] | 96 | void parseConfigValues(const SensorBaseConfigMap& entry); |
| 97 | bool sensorClassType(const std::string& sensorClass); |
| 98 | void sensorSubType(const std::string& sensorTypeName); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 99 | |
Ed Tanous | a771f6a | 2022-01-14 09:36:51 -0800 | [diff] [blame] | 100 | 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 Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 110 | std::vector<uint8_t> commandData; |
| 111 | std::optional<uint8_t> initCommand; |
| 112 | std::vector<uint8_t> initData; |
Jayashree-D | 9f6d4fd | 2021-04-13 18:27:22 +0530 | [diff] [blame] | 113 | int sensorPollMs; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 114 | |
Ed Tanous | a771f6a | 2022-01-14 09:36:51 -0800 | [diff] [blame] | 115 | ReadingFormat readingFormat = ReadingFormat::byte0; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 116 | |
| 117 | private: |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 118 | sdbusplus::asio::object_server& objectServer; |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame^] | 119 | boost::asio::steady_timer waitTimer; |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 120 | }; |