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 |
| 18 | #include <cstdint> |
| 19 | |
| 20 | #pragma pack(push, 1) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 21 | |
| 22 | struct SensorThresholdResp |
| 23 | { |
| 24 | uint8_t readable; |
| 25 | uint8_t lowernc; |
| 26 | uint8_t lowercritical; |
| 27 | uint8_t lowernonrecoverable; |
| 28 | uint8_t uppernc; |
| 29 | uint8_t uppercritical; |
| 30 | uint8_t uppernonrecoverable; |
| 31 | }; |
| 32 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 33 | struct SensorEventStatusResp |
| 34 | { |
| 35 | uint8_t enabled; |
| 36 | uint8_t assertionsLSB; |
| 37 | uint8_t assertionsMSB; |
James Feist | 392786a | 2019-03-19 13:36:10 -0700 | [diff] [blame] | 38 | uint8_t deassertionsLSB; |
| 39 | uint8_t deassertionsMSB; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 40 | }; |
| 41 | #pragma pack(pop) |
| 42 | |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 43 | enum class IPMIThresholdRespBits |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 44 | { |
| 45 | lowerNonCritical, |
| 46 | lowerCritical, |
| 47 | lowerNonRecoverable, |
| 48 | upperNonCritical, |
| 49 | upperCritical, |
| 50 | upperNonRecoverable |
| 51 | }; |
| 52 | |
| 53 | enum class IPMISensorReadingByte2 : uint8_t |
| 54 | { |
| 55 | eventMessagesEnable = (1 << 7), |
| 56 | sensorScanningEnable = (1 << 6), |
| 57 | readingStateUnavailable = (1 << 5), |
| 58 | }; |
| 59 | |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 60 | enum class IPMISensorReadingByte3 : uint8_t |
| 61 | { |
| 62 | upperNonRecoverable = (1 << 5), |
| 63 | upperCritical = (1 << 4), |
| 64 | upperNonCritical = (1 << 3), |
| 65 | lowerNonRecoverable = (1 << 2), |
| 66 | lowerCritical = (1 << 1), |
| 67 | lowerNonCritical = (1 << 0), |
| 68 | }; |
| 69 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 70 | enum class IPMISensorEventEnableByte2 : uint8_t |
| 71 | { |
| 72 | eventMessagesEnable = (1 << 7), |
| 73 | sensorScanningEnable = (1 << 6), |
| 74 | }; |
| 75 | |
| 76 | enum class IPMISensorEventEnableThresholds : uint8_t |
| 77 | { |
| 78 | upperNonRecoverableGoingHigh = (1 << 3), |
| 79 | upperNonRecoverableGoingLow = (1 << 2), |
| 80 | upperCriticalGoingHigh = (1 << 1), |
| 81 | upperCriticalGoingLow = (1 << 0), |
| 82 | upperNonCriticalGoingHigh = (1 << 7), |
| 83 | upperNonCriticalGoingLow = (1 << 6), |
| 84 | lowerNonRecoverableGoingHigh = (1 << 5), |
| 85 | lowerNonRecoverableGoingLow = (1 << 4), |
| 86 | lowerCriticalGoingHigh = (1 << 3), |
| 87 | lowerCriticalGoingLow = (1 << 2), |
| 88 | lowerNonCriticalGoingHigh = (1 << 1), |
| 89 | lowerNonCriticalGoingLow = (1 << 0), |
| 90 | }; |
| 91 | |
| 92 | enum class IPMINetfnSensorCmds : ipmi_cmd_t |
| 93 | { |
| 94 | ipmiCmdGetDeviceSDRInfo = 0x20, |
| 95 | ipmiCmdGetDeviceSDR = 0x21, |
| 96 | ipmiCmdReserveDeviceSDRRepo = 0x22, |
James Feist | fcce83d | 2019-03-01 15:46:19 -0800 | [diff] [blame] | 97 | ipmiCmdSetSensorThreshold = 0x26, |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 98 | ipmiCmdGetSensorThreshold = 0x27, |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 99 | ipmiCmdGetSensorEventEnable = 0x29, |
| 100 | ipmiCmdGetSensorEventStatus = 0x2B, |
| 101 | ipmiCmdGetSensorReading = 0x2D, |
| 102 | ipmiCmdGetSensorType = 0x2F, |
| 103 | ipmiCmdSetSensorReadingAndEventStatus = 0x30, |
| 104 | }; |
Richard Marian Thomaiyar | 01fbcb5 | 2018-11-19 22:04:34 +0530 | [diff] [blame] | 105 | |
Richard Marian Thomaiyar | 4c88d4c | 2018-12-05 20:52:43 +0530 | [diff] [blame] | 106 | namespace ipmi |
| 107 | { |
Richard Marian Thomaiyar | 01fbcb5 | 2018-11-19 22:04:34 +0530 | [diff] [blame] | 108 | extern SensorSubTree sensorTree; |
| 109 | static ipmi_ret_t getSensorConnection(uint8_t sensnum, std::string &connection, |
| 110 | std::string &path) |
| 111 | { |
| 112 | if (sensorTree.empty() && !getSensorSubtree(sensorTree)) |
| 113 | { |
| 114 | return IPMI_CC_RESPONSE_ERROR; |
| 115 | } |
| 116 | |
| 117 | if (sensorTree.size() < (sensnum + 1)) |
| 118 | { |
| 119 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 120 | } |
| 121 | |
| 122 | uint8_t sensorIndex = sensnum; |
| 123 | for (const auto &sensor : sensorTree) |
| 124 | { |
| 125 | if (sensorIndex-- == 0) |
| 126 | { |
| 127 | if (!sensor.second.size()) |
| 128 | { |
| 129 | return IPMI_CC_RESPONSE_ERROR; |
| 130 | } |
| 131 | connection = sensor.second.begin()->first; |
| 132 | path = sensor.first; |
| 133 | break; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | return 0; |
| 138 | } |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 139 | |
| 140 | struct IPMIThresholds |
| 141 | { |
| 142 | std::optional<uint8_t> warningLow; |
| 143 | std::optional<uint8_t> warningHigh; |
| 144 | std::optional<uint8_t> criticalLow; |
| 145 | std::optional<uint8_t> criticalHigh; |
| 146 | }; |
| 147 | |
Richard Marian Thomaiyar | 4c88d4c | 2018-12-05 20:52:43 +0530 | [diff] [blame] | 148 | } // namespace ipmi |