blob: 820c746641e6c70a238ec3b6526602571a0f2f1d [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
Patrick Venture14c36a82019-10-23 09:24:56 -070018#include "sdrutils.hpp"
19
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070020#include <cstdint>
Patrick Venture545fb2d2019-10-12 16:25:21 -070021#include <ipmid/api.hpp>
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070022
23#pragma pack(push, 1)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070024
25struct SensorThresholdResp
26{
27 uint8_t readable;
28 uint8_t lowernc;
29 uint8_t lowercritical;
30 uint8_t lowernonrecoverable;
31 uint8_t uppernc;
32 uint8_t uppercritical;
33 uint8_t uppernonrecoverable;
34};
35
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070036#pragma pack(pop)
37
James Feist902c4c52019-04-16 14:51:31 -070038enum class IPMIThresholdRespBits
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070039{
40 lowerNonCritical,
41 lowerCritical,
42 lowerNonRecoverable,
43 upperNonCritical,
44 upperCritical,
45 upperNonRecoverable
46};
47
48enum class IPMISensorReadingByte2 : uint8_t
49{
50 eventMessagesEnable = (1 << 7),
51 sensorScanningEnable = (1 << 6),
52 readingStateUnavailable = (1 << 5),
53};
54
James Feist0cd014a2019-04-08 15:04:33 -070055enum class IPMISensorReadingByte3 : uint8_t
56{
57 upperNonRecoverable = (1 << 5),
58 upperCritical = (1 << 4),
59 upperNonCritical = (1 << 3),
60 lowerNonRecoverable = (1 << 2),
61 lowerCritical = (1 << 1),
62 lowerNonCritical = (1 << 0),
63};
64
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070065enum class IPMISensorEventEnableByte2 : uint8_t
66{
67 eventMessagesEnable = (1 << 7),
68 sensorScanningEnable = (1 << 6),
69};
70
71enum class IPMISensorEventEnableThresholds : uint8_t
72{
Rashmi RV963a95b2020-01-27 15:09:17 +053073 nonRecoverableThreshold = (1 << 6),
74 criticalThreshold = (1 << 5),
75 nonCriticalThreshold = (1 << 4),
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070076 upperNonRecoverableGoingHigh = (1 << 3),
77 upperNonRecoverableGoingLow = (1 << 2),
78 upperCriticalGoingHigh = (1 << 1),
79 upperCriticalGoingLow = (1 << 0),
80 upperNonCriticalGoingHigh = (1 << 7),
81 upperNonCriticalGoingLow = (1 << 6),
82 lowerNonRecoverableGoingHigh = (1 << 5),
83 lowerNonRecoverableGoingLow = (1 << 4),
84 lowerCriticalGoingHigh = (1 << 3),
85 lowerCriticalGoingLow = (1 << 2),
86 lowerNonCriticalGoingHigh = (1 << 1),
87 lowerNonCriticalGoingLow = (1 << 0),
88};
89
jayaprakash Mutyalaccf88f62019-05-13 16:57:16 +000090enum class IPMIGetSensorEventEnableThresholds : uint8_t
91{
92 lowerNonCriticalGoingLow = 0,
93 lowerNonCriticalGoingHigh = 1,
94 lowerCriticalGoingLow = 2,
95 lowerCriticalGoingHigh = 3,
96 lowerNonRecoverableGoingLow = 4,
97 lowerNonRecoverableGoingHigh = 5,
98 upperNonCriticalGoingLow = 6,
99 upperNonCriticalGoingHigh = 7,
100 upperCriticalGoingLow = 8,
101 upperCriticalGoingHigh = 9,
102 upperNonRecoverableGoingLow = 10,
103 upperNonRecoverableGoingHigh = 11,
104};
105
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700106enum class IPMINetfnSensorCmds : ipmi_cmd_t
107{
108 ipmiCmdGetDeviceSDRInfo = 0x20,
109 ipmiCmdGetDeviceSDR = 0x21,
110 ipmiCmdReserveDeviceSDRRepo = 0x22,
James Feistfcce83d2019-03-01 15:46:19 -0800111 ipmiCmdSetSensorThreshold = 0x26,
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700112 ipmiCmdGetSensorThreshold = 0x27,
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700113 ipmiCmdGetSensorEventEnable = 0x29,
114 ipmiCmdGetSensorEventStatus = 0x2B,
115 ipmiCmdGetSensorReading = 0x2D,
116 ipmiCmdGetSensorType = 0x2F,
117 ipmiCmdSetSensorReadingAndEventStatus = 0x30,
118};
Richard Marian Thomaiyar01fbcb52018-11-19 22:04:34 +0530119
Richard Marian Thomaiyar4c88d4c2018-12-05 20:52:43 +0530120namespace ipmi
121{
Richard Marian Thomaiyar01fbcb52018-11-19 22:04:34 +0530122extern SensorSubTree sensorTree;
123static ipmi_ret_t getSensorConnection(uint8_t sensnum, std::string &connection,
124 std::string &path)
125{
126 if (sensorTree.empty() && !getSensorSubtree(sensorTree))
127 {
128 return IPMI_CC_RESPONSE_ERROR;
129 }
130
131 if (sensorTree.size() < (sensnum + 1))
132 {
133 return IPMI_CC_INVALID_FIELD_REQUEST;
134 }
135
136 uint8_t sensorIndex = sensnum;
137 for (const auto &sensor : sensorTree)
138 {
139 if (sensorIndex-- == 0)
140 {
141 if (!sensor.second.size())
142 {
143 return IPMI_CC_RESPONSE_ERROR;
144 }
145 connection = sensor.second.begin()->first;
146 path = sensor.first;
147 break;
148 }
149 }
150
151 return 0;
152}
James Feist902c4c52019-04-16 14:51:31 -0700153
154struct IPMIThresholds
155{
156 std::optional<uint8_t> warningLow;
157 std::optional<uint8_t> warningHigh;
158 std::optional<uint8_t> criticalLow;
159 std::optional<uint8_t> criticalHigh;
160};
161
Richard Marian Thomaiyar4c88d4c2018-12-05 20:52:43 +0530162} // namespace ipmi