Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2017 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
Patrick Venture | 14c36a8 | 2019-10-23 09:24:56 -0700 | [diff] [blame] | 18 | #include "sdrutils.hpp" |
| 19 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 20 | #include <cstdint> |
Patrick Venture | 545fb2d | 2019-10-12 16:25:21 -0700 | [diff] [blame] | 21 | #include <ipmid/api.hpp> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 22 | |
| 23 | #pragma pack(push, 1) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 24 | |
| 25 | struct SensorThresholdResp |
| 26 | { |
| 27 | uint8_t readable; |
| 28 | uint8_t lowernc; |
| 29 | uint8_t lowercritical; |
| 30 | uint8_t lowernonrecoverable; |
| 31 | uint8_t uppernc; |
| 32 | uint8_t uppercritical; |
| 33 | uint8_t uppernonrecoverable; |
| 34 | }; |
| 35 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 36 | #pragma pack(pop) |
| 37 | |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 38 | enum class IPMIThresholdRespBits |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 39 | { |
| 40 | lowerNonCritical, |
| 41 | lowerCritical, |
| 42 | lowerNonRecoverable, |
| 43 | upperNonCritical, |
| 44 | upperCritical, |
| 45 | upperNonRecoverable |
| 46 | }; |
| 47 | |
| 48 | enum class IPMISensorReadingByte2 : uint8_t |
| 49 | { |
| 50 | eventMessagesEnable = (1 << 7), |
| 51 | sensorScanningEnable = (1 << 6), |
| 52 | readingStateUnavailable = (1 << 5), |
| 53 | }; |
| 54 | |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 55 | enum class IPMISensorReadingByte3 : uint8_t |
| 56 | { |
| 57 | upperNonRecoverable = (1 << 5), |
| 58 | upperCritical = (1 << 4), |
| 59 | upperNonCritical = (1 << 3), |
| 60 | lowerNonRecoverable = (1 << 2), |
| 61 | lowerCritical = (1 << 1), |
| 62 | lowerNonCritical = (1 << 0), |
| 63 | }; |
| 64 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 65 | enum class IPMISensorEventEnableByte2 : uint8_t |
| 66 | { |
| 67 | eventMessagesEnable = (1 << 7), |
| 68 | sensorScanningEnable = (1 << 6), |
| 69 | }; |
| 70 | |
| 71 | enum class IPMISensorEventEnableThresholds : uint8_t |
| 72 | { |
Rashmi RV | 963a95b | 2020-01-27 15:09:17 +0530 | [diff] [blame^] | 73 | nonRecoverableThreshold = (1 << 6), |
| 74 | criticalThreshold = (1 << 5), |
| 75 | nonCriticalThreshold = (1 << 4), |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 76 | upperNonRecoverableGoingHigh = (1 << 3), |
| 77 | upperNonRecoverableGoingLow = (1 << 2), |
| 78 | upperCriticalGoingHigh = (1 << 1), |
| 79 | upperCriticalGoingLow = (1 << 0), |
| 80 | upperNonCriticalGoingHigh = (1 << 7), |
| 81 | upperNonCriticalGoingLow = (1 << 6), |
| 82 | lowerNonRecoverableGoingHigh = (1 << 5), |
| 83 | lowerNonRecoverableGoingLow = (1 << 4), |
| 84 | lowerCriticalGoingHigh = (1 << 3), |
| 85 | lowerCriticalGoingLow = (1 << 2), |
| 86 | lowerNonCriticalGoingHigh = (1 << 1), |
| 87 | lowerNonCriticalGoingLow = (1 << 0), |
| 88 | }; |
| 89 | |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 90 | enum class IPMIGetSensorEventEnableThresholds : uint8_t |
| 91 | { |
| 92 | lowerNonCriticalGoingLow = 0, |
| 93 | lowerNonCriticalGoingHigh = 1, |
| 94 | lowerCriticalGoingLow = 2, |
| 95 | lowerCriticalGoingHigh = 3, |
| 96 | lowerNonRecoverableGoingLow = 4, |
| 97 | lowerNonRecoverableGoingHigh = 5, |
| 98 | upperNonCriticalGoingLow = 6, |
| 99 | upperNonCriticalGoingHigh = 7, |
| 100 | upperCriticalGoingLow = 8, |
| 101 | upperCriticalGoingHigh = 9, |
| 102 | upperNonRecoverableGoingLow = 10, |
| 103 | upperNonRecoverableGoingHigh = 11, |
| 104 | }; |
| 105 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 106 | enum class IPMINetfnSensorCmds : ipmi_cmd_t |
| 107 | { |
| 108 | ipmiCmdGetDeviceSDRInfo = 0x20, |
| 109 | ipmiCmdGetDeviceSDR = 0x21, |
| 110 | ipmiCmdReserveDeviceSDRRepo = 0x22, |
James Feist | fcce83d | 2019-03-01 15:46:19 -0800 | [diff] [blame] | 111 | ipmiCmdSetSensorThreshold = 0x26, |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 112 | ipmiCmdGetSensorThreshold = 0x27, |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 113 | ipmiCmdGetSensorEventEnable = 0x29, |
| 114 | ipmiCmdGetSensorEventStatus = 0x2B, |
| 115 | ipmiCmdGetSensorReading = 0x2D, |
| 116 | ipmiCmdGetSensorType = 0x2F, |
| 117 | ipmiCmdSetSensorReadingAndEventStatus = 0x30, |
| 118 | }; |
Richard Marian Thomaiyar | 01fbcb5 | 2018-11-19 22:04:34 +0530 | [diff] [blame] | 119 | |
Richard Marian Thomaiyar | 4c88d4c | 2018-12-05 20:52:43 +0530 | [diff] [blame] | 120 | namespace ipmi |
| 121 | { |
Richard Marian Thomaiyar | 01fbcb5 | 2018-11-19 22:04:34 +0530 | [diff] [blame] | 122 | extern SensorSubTree sensorTree; |
| 123 | static ipmi_ret_t getSensorConnection(uint8_t sensnum, std::string &connection, |
| 124 | std::string &path) |
| 125 | { |
| 126 | if (sensorTree.empty() && !getSensorSubtree(sensorTree)) |
| 127 | { |
| 128 | return IPMI_CC_RESPONSE_ERROR; |
| 129 | } |
| 130 | |
| 131 | if (sensorTree.size() < (sensnum + 1)) |
| 132 | { |
| 133 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 134 | } |
| 135 | |
| 136 | uint8_t sensorIndex = sensnum; |
| 137 | for (const auto &sensor : sensorTree) |
| 138 | { |
| 139 | if (sensorIndex-- == 0) |
| 140 | { |
| 141 | if (!sensor.second.size()) |
| 142 | { |
| 143 | return IPMI_CC_RESPONSE_ERROR; |
| 144 | } |
| 145 | connection = sensor.second.begin()->first; |
| 146 | path = sensor.first; |
| 147 | break; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | return 0; |
| 152 | } |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 153 | |
| 154 | struct IPMIThresholds |
| 155 | { |
| 156 | std::optional<uint8_t> warningLow; |
| 157 | std::optional<uint8_t> warningHigh; |
| 158 | std::optional<uint8_t> criticalLow; |
| 159 | std::optional<uint8_t> criticalHigh; |
| 160 | }; |
| 161 | |
Richard Marian Thomaiyar | 4c88d4c | 2018-12-05 20:52:43 +0530 | [diff] [blame] | 162 | } // namespace ipmi |