blob: 66536c2865fecf526cc9744c8dabb71adb60a19e [file] [log] [blame]
Jason M. Bills3f7c5e42018-10-03 14:00:41 -07001/*
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)
21struct SensorReadingResp
22{
23 uint8_t value;
24 uint8_t operation;
25 uint8_t indication[2];
26};
27
28struct SensorThresholdResp
29{
30 uint8_t readable;
31 uint8_t lowernc;
32 uint8_t lowercritical;
33 uint8_t lowernonrecoverable;
34 uint8_t uppernc;
35 uint8_t uppercritical;
36 uint8_t uppernonrecoverable;
37};
38
39struct SensorThresholdReq
40{
41 uint8_t sensorNum;
42 uint8_t mask;
43 uint8_t lowerNonCritical;
44 uint8_t lowerCritical;
45 uint8_t lowerNonRecoverable;
46 uint8_t upperNonCritical;
47 uint8_t upperCritical;
48 uint8_t upperNonRecoverable;
49};
50#pragma pack(pop)
51
52enum class SensorThresholdReqEnable : uint8_t
53{
54 setLowerNonCritical = 0x1,
55 setLowerCritical = 0x2,
56 setLowerNonRecoverable = 0x4,
57 setUpperNonCritical = 0x8,
58 setUpperCritical = 0x10,
59 setUpperNonRecoverable = 0x20
60};
61
62#pragma pack(push, 1)
63struct SensorEventEnableResp
64{
65 uint8_t enabled;
66 uint8_t assertionEnabledLSB;
67 uint8_t assertionEnabledMSB;
68 uint8_t deassertionEnabledLSB;
69 uint8_t deassertionEnabledMSB;
70};
71
72struct SensorEventStatusResp
73{
74 uint8_t enabled;
75 uint8_t assertionsLSB;
76 uint8_t assertionsMSB;
77 // deassertion events currently not supported
78 // uint8_t deassertionsLSB;
79 // uint8_t deassertionsMSB;
80};
81#pragma pack(pop)
82
83enum class IPMIhresholdRespBits
84{
85 lowerNonCritical,
86 lowerCritical,
87 lowerNonRecoverable,
88 upperNonCritical,
89 upperCritical,
90 upperNonRecoverable
91};
92
93enum class IPMISensorReadingByte2 : uint8_t
94{
95 eventMessagesEnable = (1 << 7),
96 sensorScanningEnable = (1 << 6),
97 readingStateUnavailable = (1 << 5),
98};
99
100enum class IPMISensorEventEnableByte2 : uint8_t
101{
102 eventMessagesEnable = (1 << 7),
103 sensorScanningEnable = (1 << 6),
104};
105
106enum class IPMISensorEventEnableThresholds : uint8_t
107{
108 upperNonRecoverableGoingHigh = (1 << 3),
109 upperNonRecoverableGoingLow = (1 << 2),
110 upperCriticalGoingHigh = (1 << 1),
111 upperCriticalGoingLow = (1 << 0),
112 upperNonCriticalGoingHigh = (1 << 7),
113 upperNonCriticalGoingLow = (1 << 6),
114 lowerNonRecoverableGoingHigh = (1 << 5),
115 lowerNonRecoverableGoingLow = (1 << 4),
116 lowerCriticalGoingHigh = (1 << 3),
117 lowerCriticalGoingLow = (1 << 2),
118 lowerNonCriticalGoingHigh = (1 << 1),
119 lowerNonCriticalGoingLow = (1 << 0),
120};
121
122enum class IPMINetfnSensorCmds : ipmi_cmd_t
123{
124 ipmiCmdGetDeviceSDRInfo = 0x20,
125 ipmiCmdGetDeviceSDR = 0x21,
126 ipmiCmdReserveDeviceSDRRepo = 0x22,
127 ipmiCmdGetSensorThreshold = 0x27,
128 ipmiCmdSetSensorThreshold = 0x28,
129 ipmiCmdGetSensorEventEnable = 0x29,
130 ipmiCmdGetSensorEventStatus = 0x2B,
131 ipmiCmdGetSensorReading = 0x2D,
132 ipmiCmdGetSensorType = 0x2F,
133 ipmiCmdSetSensorReadingAndEventStatus = 0x30,
134};
Richard Marian Thomaiyar01fbcb52018-11-19 22:04:34 +0530135
Richard Marian Thomaiyar4c88d4c2018-12-05 20:52:43 +0530136namespace ipmi
137{
Richard Marian Thomaiyar01fbcb52018-11-19 22:04:34 +0530138extern SensorSubTree sensorTree;
139static ipmi_ret_t getSensorConnection(uint8_t sensnum, std::string &connection,
140 std::string &path)
141{
142 if (sensorTree.empty() && !getSensorSubtree(sensorTree))
143 {
144 return IPMI_CC_RESPONSE_ERROR;
145 }
146
147 if (sensorTree.size() < (sensnum + 1))
148 {
149 return IPMI_CC_INVALID_FIELD_REQUEST;
150 }
151
152 uint8_t sensorIndex = sensnum;
153 for (const auto &sensor : sensorTree)
154 {
155 if (sensorIndex-- == 0)
156 {
157 if (!sensor.second.size())
158 {
159 return IPMI_CC_RESPONSE_ERROR;
160 }
161 connection = sensor.second.begin()->first;
162 path = sensor.first;
163 break;
164 }
165 }
166
167 return 0;
168}
Richard Marian Thomaiyar4c88d4c2018-12-05 20:52:43 +0530169} // namespace ipmi