blob: 0bcd6f967ca75003ce4f5dea254e1cd5c61b465a [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>
Patrick Venture545fb2d2019-10-12 16:25:21 -070019#include <ipmid/api.hpp>
20#include <sdrutils.hpp>
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070021
22#pragma pack(push, 1)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070023
24struct 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
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070035struct SensorEventStatusResp
36{
37 uint8_t enabled;
38 uint8_t assertionsLSB;
39 uint8_t assertionsMSB;
James Feist392786a2019-03-19 13:36:10 -070040 uint8_t deassertionsLSB;
41 uint8_t deassertionsMSB;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070042};
43#pragma pack(pop)
44
James Feist902c4c52019-04-16 14:51:31 -070045enum class IPMIThresholdRespBits
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070046{
47 lowerNonCritical,
48 lowerCritical,
49 lowerNonRecoverable,
50 upperNonCritical,
51 upperCritical,
52 upperNonRecoverable
53};
54
55enum class IPMISensorReadingByte2 : uint8_t
56{
57 eventMessagesEnable = (1 << 7),
58 sensorScanningEnable = (1 << 6),
59 readingStateUnavailable = (1 << 5),
60};
61
James Feist0cd014a2019-04-08 15:04:33 -070062enum class IPMISensorReadingByte3 : uint8_t
63{
64 upperNonRecoverable = (1 << 5),
65 upperCritical = (1 << 4),
66 upperNonCritical = (1 << 3),
67 lowerNonRecoverable = (1 << 2),
68 lowerCritical = (1 << 1),
69 lowerNonCritical = (1 << 0),
70};
71
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070072enum class IPMISensorEventEnableByte2 : uint8_t
73{
74 eventMessagesEnable = (1 << 7),
75 sensorScanningEnable = (1 << 6),
76};
77
78enum class IPMISensorEventEnableThresholds : uint8_t
79{
80 upperNonRecoverableGoingHigh = (1 << 3),
81 upperNonRecoverableGoingLow = (1 << 2),
82 upperCriticalGoingHigh = (1 << 1),
83 upperCriticalGoingLow = (1 << 0),
84 upperNonCriticalGoingHigh = (1 << 7),
85 upperNonCriticalGoingLow = (1 << 6),
86 lowerNonRecoverableGoingHigh = (1 << 5),
87 lowerNonRecoverableGoingLow = (1 << 4),
88 lowerCriticalGoingHigh = (1 << 3),
89 lowerCriticalGoingLow = (1 << 2),
90 lowerNonCriticalGoingHigh = (1 << 1),
91 lowerNonCriticalGoingLow = (1 << 0),
92};
93
94enum class IPMINetfnSensorCmds : ipmi_cmd_t
95{
96 ipmiCmdGetDeviceSDRInfo = 0x20,
97 ipmiCmdGetDeviceSDR = 0x21,
98 ipmiCmdReserveDeviceSDRRepo = 0x22,
James Feistfcce83d2019-03-01 15:46:19 -080099 ipmiCmdSetSensorThreshold = 0x26,
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700100 ipmiCmdGetSensorThreshold = 0x27,
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700101 ipmiCmdGetSensorEventEnable = 0x29,
102 ipmiCmdGetSensorEventStatus = 0x2B,
103 ipmiCmdGetSensorReading = 0x2D,
104 ipmiCmdGetSensorType = 0x2F,
105 ipmiCmdSetSensorReadingAndEventStatus = 0x30,
106};
Richard Marian Thomaiyar01fbcb52018-11-19 22:04:34 +0530107
Richard Marian Thomaiyar4c88d4c2018-12-05 20:52:43 +0530108namespace ipmi
109{
Richard Marian Thomaiyar01fbcb52018-11-19 22:04:34 +0530110extern SensorSubTree sensorTree;
111static ipmi_ret_t getSensorConnection(uint8_t sensnum, std::string &connection,
112 std::string &path)
113{
114 if (sensorTree.empty() && !getSensorSubtree(sensorTree))
115 {
116 return IPMI_CC_RESPONSE_ERROR;
117 }
118
119 if (sensorTree.size() < (sensnum + 1))
120 {
121 return IPMI_CC_INVALID_FIELD_REQUEST;
122 }
123
124 uint8_t sensorIndex = sensnum;
125 for (const auto &sensor : sensorTree)
126 {
127 if (sensorIndex-- == 0)
128 {
129 if (!sensor.second.size())
130 {
131 return IPMI_CC_RESPONSE_ERROR;
132 }
133 connection = sensor.second.begin()->first;
134 path = sensor.first;
135 break;
136 }
137 }
138
139 return 0;
140}
James Feist902c4c52019-04-16 14:51:31 -0700141
142struct IPMIThresholds
143{
144 std::optional<uint8_t> warningLow;
145 std::optional<uint8_t> warningHigh;
146 std::optional<uint8_t> criticalLow;
147 std::optional<uint8_t> criticalHigh;
148};
149
Richard Marian Thomaiyar4c88d4c2018-12-05 20:52:43 +0530150} // namespace ipmi