blob: c0d78534346c75b14d1fb9e750b5763fe4f96997 [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
Patrick Venture545fb2d2019-10-12 16:25:21 -070020#include <ipmid/api.hpp>
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070021
James Feistfcd2d3a2020-05-28 10:38:15 -070022#include <cstdint>
23
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070024#pragma pack(push, 1)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070025
26struct 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. Bills3f7c5e42018-10-03 14:00:41 -070037#pragma pack(pop)
38
James Feist902c4c52019-04-16 14:51:31 -070039enum class IPMIThresholdRespBits
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070040{
41 lowerNonCritical,
42 lowerCritical,
43 lowerNonRecoverable,
44 upperNonCritical,
45 upperCritical,
46 upperNonRecoverable
47};
48
49enum class IPMISensorReadingByte2 : uint8_t
50{
51 eventMessagesEnable = (1 << 7),
52 sensorScanningEnable = (1 << 6),
53 readingStateUnavailable = (1 << 5),
54};
55
James Feist0cd014a2019-04-08 15:04:33 -070056enum 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. Bills3f7c5e42018-10-03 14:00:41 -070066enum class IPMISensorEventEnableByte2 : uint8_t
67{
68 eventMessagesEnable = (1 << 7),
69 sensorScanningEnable = (1 << 6),
70};
71
72enum class IPMISensorEventEnableThresholds : uint8_t
73{
Rashmi RV963a95b2020-01-27 15:09:17 +053074 nonRecoverableThreshold = (1 << 6),
75 criticalThreshold = (1 << 5),
76 nonCriticalThreshold = (1 << 4),
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070077 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 Mutyalaccf88f62019-05-13 16:57:16 +000091enum 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. Bills3f7c5e42018-10-03 14:00:41 -0700107enum class IPMINetfnSensorCmds : ipmi_cmd_t
108{
109 ipmiCmdGetDeviceSDRInfo = 0x20,
110 ipmiCmdGetDeviceSDR = 0x21,
111 ipmiCmdReserveDeviceSDRRepo = 0x22,
James Feistfcce83d2019-03-01 15:46:19 -0800112 ipmiCmdSetSensorThreshold = 0x26,
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700113 ipmiCmdGetSensorThreshold = 0x27,
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700114 ipmiCmdGetSensorEventEnable = 0x29,
115 ipmiCmdGetSensorEventStatus = 0x2B,
116 ipmiCmdGetSensorReading = 0x2D,
117 ipmiCmdGetSensorType = 0x2F,
118 ipmiCmdSetSensorReadingAndEventStatus = 0x30,
119};
Richard Marian Thomaiyar01fbcb52018-11-19 22:04:34 +0530120
Richard Marian Thomaiyar4c88d4c2018-12-05 20:52:43 +0530121namespace ipmi
122{
Richard Marian Thomaiyar01fbcb52018-11-19 22:04:34 +0530123extern SensorSubTree sensorTree;
James Feistfcd2d3a2020-05-28 10:38:15 -0700124static ipmi_ret_t getSensorConnection(uint8_t sensnum, std::string& connection,
125 std::string& path)
Richard Marian Thomaiyar01fbcb52018-11-19 22:04:34 +0530126{
127 if (sensorTree.empty() && !getSensorSubtree(sensorTree))
128 {
129 return IPMI_CC_RESPONSE_ERROR;
130 }
131
132 if (sensorTree.size() < (sensnum + 1))
133 {
134 return IPMI_CC_INVALID_FIELD_REQUEST;
135 }
136
137 uint8_t sensorIndex = sensnum;
James Feistfcd2d3a2020-05-28 10:38:15 -0700138 for (const auto& sensor : sensorTree)
Richard Marian Thomaiyar01fbcb52018-11-19 22:04:34 +0530139 {
140 if (sensorIndex-- == 0)
141 {
142 if (!sensor.second.size())
143 {
144 return IPMI_CC_RESPONSE_ERROR;
145 }
146 connection = sensor.second.begin()->first;
147 path = sensor.first;
148 break;
149 }
150 }
151
152 return 0;
153}
James Feist902c4c52019-04-16 14:51:31 -0700154
155struct IPMIThresholds
156{
157 std::optional<uint8_t> warningLow;
158 std::optional<uint8_t> warningHigh;
159 std::optional<uint8_t> criticalLow;
160 std::optional<uint8_t> criticalHigh;
161};
162
Richard Marian Thomaiyar4c88d4c2018-12-05 20:52:43 +0530163} // namespace ipmi