blob: 7eab327c6db605cd41e625dc5d33be4b2841b486 [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)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070021
22struct 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. Bills3f7c5e42018-10-03 14:00:41 -070033struct SensorEventStatusResp
34{
35 uint8_t enabled;
36 uint8_t assertionsLSB;
37 uint8_t assertionsMSB;
James Feist392786a2019-03-19 13:36:10 -070038 uint8_t deassertionsLSB;
39 uint8_t deassertionsMSB;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070040};
41#pragma pack(pop)
42
James Feist902c4c52019-04-16 14:51:31 -070043enum class IPMIThresholdRespBits
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070044{
45 lowerNonCritical,
46 lowerCritical,
47 lowerNonRecoverable,
48 upperNonCritical,
49 upperCritical,
50 upperNonRecoverable
51};
52
53enum class IPMISensorReadingByte2 : uint8_t
54{
55 eventMessagesEnable = (1 << 7),
56 sensorScanningEnable = (1 << 6),
57 readingStateUnavailable = (1 << 5),
58};
59
James Feist0cd014a2019-04-08 15:04:33 -070060enum 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. Bills3f7c5e42018-10-03 14:00:41 -070070enum class IPMISensorEventEnableByte2 : uint8_t
71{
72 eventMessagesEnable = (1 << 7),
73 sensorScanningEnable = (1 << 6),
74};
75
76enum 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
92enum class IPMINetfnSensorCmds : ipmi_cmd_t
93{
94 ipmiCmdGetDeviceSDRInfo = 0x20,
95 ipmiCmdGetDeviceSDR = 0x21,
96 ipmiCmdReserveDeviceSDRRepo = 0x22,
James Feistfcce83d2019-03-01 15:46:19 -080097 ipmiCmdSetSensorThreshold = 0x26,
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070098 ipmiCmdGetSensorThreshold = 0x27,
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070099 ipmiCmdGetSensorEventEnable = 0x29,
100 ipmiCmdGetSensorEventStatus = 0x2B,
101 ipmiCmdGetSensorReading = 0x2D,
102 ipmiCmdGetSensorType = 0x2F,
103 ipmiCmdSetSensorReadingAndEventStatus = 0x30,
104};
Richard Marian Thomaiyar01fbcb52018-11-19 22:04:34 +0530105
Richard Marian Thomaiyar4c88d4c2018-12-05 20:52:43 +0530106namespace ipmi
107{
Richard Marian Thomaiyar01fbcb52018-11-19 22:04:34 +0530108extern SensorSubTree sensorTree;
109static 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 Feist902c4c52019-04-16 14:51:31 -0700139
140struct 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 Thomaiyar4c88d4c2018-12-05 20:52:43 +0530148} // namespace ipmi