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 | |
Patrick Williams | d02ad49 | 2023-05-08 09:15:21 -0500 | [diff] [blame] | 49 | static inline bool isValid(const std::vector<uint8_t>& data) |
Adrian Ambrożewicz | 58e02ef | 2020-08-06 14:42:38 +0200 | [diff] [blame] | 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 | |
Vikash Chandola | 1f84797 | 2022-09-28 09:47:32 +0000 | [diff] [blame] | 78 | using IpmbMethodType = |
| 79 | std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>; |
| 80 | |
| 81 | struct IpmbSensor : |
| 82 | public Sensor, |
| 83 | public std::enable_shared_from_this<IpmbSensor> |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 84 | { |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 85 | IpmbSensor(std::shared_ptr<sdbusplus::asio::connection>& conn, |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 86 | boost::asio::io_context& io, const std::string& name, |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 87 | const std::string& sensorConfiguration, |
| 88 | sdbusplus::asio::object_server& objectServer, |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 89 | std::vector<thresholds::Threshold>&& thresholdData, |
| 90 | uint8_t deviceAddress, uint8_t hostSMbusIndex, float pollRate, |
| 91 | std::string& sensorTypeName); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 92 | ~IpmbSensor() override; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 93 | |
| 94 | void checkThresholds(void) override; |
| 95 | void read(void); |
| 96 | void init(void); |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 97 | std::string getSubTypeUnits(void) const; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 98 | void loadDefaults(void); |
James Feist | f7e2c5d | 2019-02-13 17:27:51 -0800 | [diff] [blame] | 99 | void runInitCmd(void); |
James Feist | 961bf09 | 2020-07-01 16:38:12 -0700 | [diff] [blame] | 100 | bool processReading(const std::vector<uint8_t>& data, double& resp); |
Jayashree Dhanapal | 8418975 | 2022-03-07 12:51:54 +0530 | [diff] [blame] | 101 | void parseConfigValues(const SensorBaseConfigMap& entry); |
| 102 | bool sensorClassType(const std::string& sensorClass); |
| 103 | void sensorSubType(const std::string& sensorTypeName); |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 104 | |
Ed Tanous | a771f6a | 2022-01-14 09:36:51 -0800 | [diff] [blame] | 105 | IpmbType type = IpmbType::none; |
| 106 | IpmbSubType subType = IpmbSubType::none; |
| 107 | double scaleVal = 1.0; |
| 108 | double offsetVal = 0.0; |
| 109 | uint8_t commandAddress = 0; |
| 110 | uint8_t netfn = 0; |
| 111 | uint8_t command = 0; |
| 112 | uint8_t deviceAddress = 0; |
| 113 | uint8_t errorCount = 0; |
| 114 | uint8_t hostSMbusIndex = 0; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 115 | std::vector<uint8_t> commandData; |
| 116 | std::optional<uint8_t> initCommand; |
| 117 | std::vector<uint8_t> initData; |
Jayashree-D | 9f6d4fd | 2021-04-13 18:27:22 +0530 | [diff] [blame] | 118 | int sensorPollMs; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 119 | |
Ed Tanous | a771f6a | 2022-01-14 09:36:51 -0800 | [diff] [blame] | 120 | ReadingFormat readingFormat = ReadingFormat::byte0; |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 121 | |
| 122 | private: |
Vikash Chandola | 1f84797 | 2022-09-28 09:47:32 +0000 | [diff] [blame] | 123 | void sendIpmbRequest(void); |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 124 | sdbusplus::asio::object_server& objectServer; |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 125 | boost::asio::steady_timer waitTimer; |
Vikash Chandola | 1f84797 | 2022-09-28 09:47:32 +0000 | [diff] [blame] | 126 | void ipmbRequestCompletionCb(const boost::system::error_code& ec, |
| 127 | const IpmbMethodType& response); |
Vijay Khemka | 682a5cb | 2019-07-18 17:34:03 -0700 | [diff] [blame] | 128 | }; |