blob: 21349e925346bbecbc59baf9a3fb3a6b16032b35 [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{
73 upperNonRecoverableGoingHigh = (1 << 3),
74 upperNonRecoverableGoingLow = (1 << 2),
75 upperCriticalGoingHigh = (1 << 1),
76 upperCriticalGoingLow = (1 << 0),
77 upperNonCriticalGoingHigh = (1 << 7),
78 upperNonCriticalGoingLow = (1 << 6),
79 lowerNonRecoverableGoingHigh = (1 << 5),
80 lowerNonRecoverableGoingLow = (1 << 4),
81 lowerCriticalGoingHigh = (1 << 3),
82 lowerCriticalGoingLow = (1 << 2),
83 lowerNonCriticalGoingHigh = (1 << 1),
84 lowerNonCriticalGoingLow = (1 << 0),
85};
86
jayaprakash Mutyalaccf88f62019-05-13 16:57:16 +000087enum class IPMIGetSensorEventEnableThresholds : uint8_t
88{
89 lowerNonCriticalGoingLow = 0,
90 lowerNonCriticalGoingHigh = 1,
91 lowerCriticalGoingLow = 2,
92 lowerCriticalGoingHigh = 3,
93 lowerNonRecoverableGoingLow = 4,
94 lowerNonRecoverableGoingHigh = 5,
95 upperNonCriticalGoingLow = 6,
96 upperNonCriticalGoingHigh = 7,
97 upperCriticalGoingLow = 8,
98 upperCriticalGoingHigh = 9,
99 upperNonRecoverableGoingLow = 10,
100 upperNonRecoverableGoingHigh = 11,
101};
102
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700103enum class IPMINetfnSensorCmds : ipmi_cmd_t
104{
105 ipmiCmdGetDeviceSDRInfo = 0x20,
106 ipmiCmdGetDeviceSDR = 0x21,
107 ipmiCmdReserveDeviceSDRRepo = 0x22,
James Feistfcce83d2019-03-01 15:46:19 -0800108 ipmiCmdSetSensorThreshold = 0x26,
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700109 ipmiCmdGetSensorThreshold = 0x27,
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700110 ipmiCmdGetSensorEventEnable = 0x29,
111 ipmiCmdGetSensorEventStatus = 0x2B,
112 ipmiCmdGetSensorReading = 0x2D,
113 ipmiCmdGetSensorType = 0x2F,
114 ipmiCmdSetSensorReadingAndEventStatus = 0x30,
115};
Richard Marian Thomaiyar01fbcb52018-11-19 22:04:34 +0530116
Richard Marian Thomaiyar4c88d4c2018-12-05 20:52:43 +0530117namespace ipmi
118{
Richard Marian Thomaiyar01fbcb52018-11-19 22:04:34 +0530119extern SensorSubTree sensorTree;
120static ipmi_ret_t getSensorConnection(uint8_t sensnum, std::string &connection,
121 std::string &path)
122{
123 if (sensorTree.empty() && !getSensorSubtree(sensorTree))
124 {
125 return IPMI_CC_RESPONSE_ERROR;
126 }
127
128 if (sensorTree.size() < (sensnum + 1))
129 {
130 return IPMI_CC_INVALID_FIELD_REQUEST;
131 }
132
133 uint8_t sensorIndex = sensnum;
134 for (const auto &sensor : sensorTree)
135 {
136 if (sensorIndex-- == 0)
137 {
138 if (!sensor.second.size())
139 {
140 return IPMI_CC_RESPONSE_ERROR;
141 }
142 connection = sensor.second.begin()->first;
143 path = sensor.first;
144 break;
145 }
146 }
147
148 return 0;
149}
James Feist902c4c52019-04-16 14:51:31 -0700150
151struct IPMIThresholds
152{
153 std::optional<uint8_t> warningLow;
154 std::optional<uint8_t> warningHigh;
155 std::optional<uint8_t> criticalLow;
156 std::optional<uint8_t> criticalHigh;
157};
158
Richard Marian Thomaiyar4c88d4c2018-12-05 20:52:43 +0530159} // namespace ipmi