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