Willy Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [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 |
Willy Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 18 | #include <dbus-sdr/sdrutils.hpp> |
| 19 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 20 | #include <cstdint> |
| 21 | |
Willy Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 22 | #pragma pack(push, 1) |
| 23 | |
| 24 | struct SensorThresholdResp |
| 25 | { |
| 26 | uint8_t readable; |
| 27 | uint8_t lowernc; |
| 28 | uint8_t lowercritical; |
| 29 | uint8_t lowernonrecoverable; |
| 30 | uint8_t uppernc; |
| 31 | uint8_t uppercritical; |
| 32 | uint8_t uppernonrecoverable; |
| 33 | }; |
| 34 | |
| 35 | #pragma pack(pop) |
| 36 | |
| 37 | enum class IPMIThresholdRespBits |
| 38 | { |
| 39 | lowerNonCritical, |
| 40 | lowerCritical, |
| 41 | lowerNonRecoverable, |
| 42 | upperNonCritical, |
| 43 | upperCritical, |
| 44 | upperNonRecoverable |
| 45 | }; |
| 46 | |
| 47 | enum class IPMISensorReadingByte2 : uint8_t |
| 48 | { |
| 49 | eventMessagesEnable = (1 << 7), |
| 50 | sensorScanningEnable = (1 << 6), |
| 51 | readingStateUnavailable = (1 << 5), |
| 52 | }; |
| 53 | |
| 54 | enum class IPMISensorReadingByte3 : uint8_t |
| 55 | { |
| 56 | upperNonRecoverable = (1 << 5), |
| 57 | upperCritical = (1 << 4), |
| 58 | upperNonCritical = (1 << 3), |
| 59 | lowerNonRecoverable = (1 << 2), |
| 60 | lowerCritical = (1 << 1), |
| 61 | lowerNonCritical = (1 << 0), |
| 62 | }; |
| 63 | |
| 64 | enum class IPMISensorEventEnableByte2 : uint8_t |
| 65 | { |
| 66 | eventMessagesEnable = (1 << 7), |
| 67 | sensorScanningEnable = (1 << 6), |
| 68 | }; |
| 69 | |
| 70 | enum class IPMISensorEventEnableThresholds : uint8_t |
| 71 | { |
| 72 | nonRecoverableThreshold = (1 << 6), |
| 73 | criticalThreshold = (1 << 5), |
| 74 | nonCriticalThreshold = (1 << 4), |
| 75 | upperNonRecoverableGoingHigh = (1 << 3), |
| 76 | upperNonRecoverableGoingLow = (1 << 2), |
| 77 | upperCriticalGoingHigh = (1 << 1), |
| 78 | upperCriticalGoingLow = (1 << 0), |
| 79 | upperNonCriticalGoingHigh = (1 << 7), |
| 80 | upperNonCriticalGoingLow = (1 << 6), |
| 81 | lowerNonRecoverableGoingHigh = (1 << 5), |
| 82 | lowerNonRecoverableGoingLow = (1 << 4), |
| 83 | lowerCriticalGoingHigh = (1 << 3), |
| 84 | lowerCriticalGoingLow = (1 << 2), |
| 85 | lowerNonCriticalGoingHigh = (1 << 1), |
| 86 | lowerNonCriticalGoingLow = (1 << 0), |
| 87 | }; |
| 88 | |
| 89 | enum class IPMIGetSensorEventEnableThresholds : uint8_t |
| 90 | { |
| 91 | lowerNonCriticalGoingLow = 0, |
| 92 | lowerNonCriticalGoingHigh = 1, |
| 93 | lowerCriticalGoingLow = 2, |
| 94 | lowerCriticalGoingHigh = 3, |
| 95 | lowerNonRecoverableGoingLow = 4, |
| 96 | lowerNonRecoverableGoingHigh = 5, |
| 97 | upperNonCriticalGoingLow = 6, |
| 98 | upperNonCriticalGoingHigh = 7, |
| 99 | upperCriticalGoingLow = 8, |
| 100 | upperCriticalGoingHigh = 9, |
| 101 | upperNonRecoverableGoingLow = 10, |
| 102 | upperNonRecoverableGoingHigh = 11, |
| 103 | }; |
| 104 | |
| 105 | enum class IPMINetfnSensorCmds : ipmi_cmd_t |
| 106 | { |
| 107 | ipmiCmdGetDeviceSDRInfo = 0x20, |
| 108 | ipmiCmdGetDeviceSDR = 0x21, |
| 109 | ipmiCmdReserveDeviceSDRRepo = 0x22, |
| 110 | ipmiCmdSetSensorThreshold = 0x26, |
| 111 | ipmiCmdGetSensorThreshold = 0x27, |
| 112 | ipmiCmdGetSensorEventEnable = 0x29, |
| 113 | ipmiCmdGetSensorEventStatus = 0x2B, |
| 114 | ipmiCmdGetSensorReading = 0x2D, |
| 115 | ipmiCmdGetSensorType = 0x2F, |
| 116 | ipmiCmdSetSensorReadingAndEventStatus = 0x30, |
| 117 | }; |
| 118 | |
| 119 | namespace ipmi |
| 120 | { |
| 121 | |
| 122 | SensorSubTree& getSensorTree() |
| 123 | { |
| 124 | static SensorSubTree sensorTree; |
| 125 | return sensorTree; |
| 126 | } |
| 127 | |
Hao Jiang | e39d4d8 | 2021-04-16 17:02:40 -0700 | [diff] [blame] | 128 | static ipmi_ret_t |
Johnathan Mantey | 6619ae4 | 2021-08-06 11:21:10 -0700 | [diff] [blame] | 129 | getSensorConnection(ipmi::Context::ptr ctx, uint8_t sensnum, |
Hao Jiang | e39d4d8 | 2021-04-16 17:02:40 -0700 | [diff] [blame] | 130 | std::string& connection, std::string& path, |
| 131 | std::vector<std::string>* interfaces = nullptr) |
Willy Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 132 | { |
| 133 | auto& sensorTree = getSensorTree(); |
Kuiying Wang | a8b5b26 | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 134 | if (!getSensorSubtree(sensorTree) && sensorTree.empty()) |
Willy Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 135 | { |
| 136 | return IPMI_CC_RESPONSE_ERROR; |
| 137 | } |
| 138 | |
| 139 | if (ctx == nullptr) |
| 140 | { |
| 141 | return IPMI_CC_RESPONSE_ERROR; |
| 142 | } |
| 143 | |
| 144 | path = getPathFromSensorNumber((ctx->lun << 8) | sensnum); |
| 145 | if (path.empty()) |
| 146 | { |
| 147 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 148 | } |
| 149 | |
| 150 | for (const auto& sensor : sensorTree) |
| 151 | { |
| 152 | if (path == sensor.first) |
| 153 | { |
| 154 | connection = sensor.second.begin()->first; |
Hao Jiang | e39d4d8 | 2021-04-16 17:02:40 -0700 | [diff] [blame] | 155 | if (interfaces) |
| 156 | *interfaces = sensor.second.begin()->second; |
Willy Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 157 | break; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | struct IPMIThresholds |
| 165 | { |
| 166 | std::optional<uint8_t> warningLow; |
| 167 | std::optional<uint8_t> warningHigh; |
| 168 | std::optional<uint8_t> criticalLow; |
| 169 | std::optional<uint8_t> criticalHigh; |
| 170 | }; |
| 171 | |
| 172 | } // namespace ipmi |