blob: cde3ffb1b8523078fecdea94aa2d13936703f67a [file] [log] [blame]
Willy Tude54f482021-01-26 15:59:09 -08001/*
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
Willy Tude54f482021-01-26 15:59:09 -080018#include <dbus-sdr/sdrutils.hpp>
19
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050020#include <cstdint>
21
Willy Tude54f482021-01-26 15:59:09 -080022#pragma pack(push, 1)
23
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
35#pragma pack(pop)
36
37enum class IPMIThresholdRespBits
38{
39 lowerNonCritical,
40 lowerCritical,
41 lowerNonRecoverable,
42 upperNonCritical,
43 upperCritical,
44 upperNonRecoverable
45};
46
47enum class IPMISensorReadingByte2 : uint8_t
48{
49 eventMessagesEnable = (1 << 7),
50 sensorScanningEnable = (1 << 6),
51 readingStateUnavailable = (1 << 5),
52};
53
54enum class IPMISensorReadingByte3 : uint8_t
55{
56 upperNonRecoverable = (1 << 5),
57 upperCritical = (1 << 4),
58 upperNonCritical = (1 << 3),
59 lowerNonRecoverable = (1 << 2),
60 lowerCritical = (1 << 1),
61 lowerNonCritical = (1 << 0),
62};
63
64enum class IPMISensorEventEnableByte2 : uint8_t
65{
66 eventMessagesEnable = (1 << 7),
67 sensorScanningEnable = (1 << 6),
68};
69
70enum class IPMISensorEventEnableThresholds : uint8_t
71{
72 nonRecoverableThreshold = (1 << 6),
73 criticalThreshold = (1 << 5),
74 nonCriticalThreshold = (1 << 4),
75 upperNonRecoverableGoingHigh = (1 << 3),
76 upperNonRecoverableGoingLow = (1 << 2),
77 upperCriticalGoingHigh = (1 << 1),
78 upperCriticalGoingLow = (1 << 0),
79 upperNonCriticalGoingHigh = (1 << 7),
80 upperNonCriticalGoingLow = (1 << 6),
81 lowerNonRecoverableGoingHigh = (1 << 5),
82 lowerNonRecoverableGoingLow = (1 << 4),
83 lowerCriticalGoingHigh = (1 << 3),
84 lowerCriticalGoingLow = (1 << 2),
85 lowerNonCriticalGoingHigh = (1 << 1),
86 lowerNonCriticalGoingLow = (1 << 0),
87};
88
89enum class IPMIGetSensorEventEnableThresholds : uint8_t
90{
91 lowerNonCriticalGoingLow = 0,
92 lowerNonCriticalGoingHigh = 1,
93 lowerCriticalGoingLow = 2,
94 lowerCriticalGoingHigh = 3,
95 lowerNonRecoverableGoingLow = 4,
96 lowerNonRecoverableGoingHigh = 5,
97 upperNonCriticalGoingLow = 6,
98 upperNonCriticalGoingHigh = 7,
99 upperCriticalGoingLow = 8,
100 upperCriticalGoingHigh = 9,
101 upperNonRecoverableGoingLow = 10,
102 upperNonRecoverableGoingHigh = 11,
103};
104
105enum class IPMINetfnSensorCmds : ipmi_cmd_t
106{
107 ipmiCmdGetDeviceSDRInfo = 0x20,
108 ipmiCmdGetDeviceSDR = 0x21,
109 ipmiCmdReserveDeviceSDRRepo = 0x22,
110 ipmiCmdSetSensorThreshold = 0x26,
111 ipmiCmdGetSensorThreshold = 0x27,
112 ipmiCmdGetSensorEventEnable = 0x29,
113 ipmiCmdGetSensorEventStatus = 0x2B,
114 ipmiCmdGetSensorReading = 0x2D,
115 ipmiCmdGetSensorType = 0x2F,
116 ipmiCmdSetSensorReadingAndEventStatus = 0x30,
117};
118
119namespace ipmi
120{
121
122SensorSubTree& getSensorTree()
123{
124 static SensorSubTree sensorTree;
125 return sensorTree;
126}
127
Hao Jiange39d4d82021-04-16 17:02:40 -0700128static ipmi_ret_t
Johnathan Mantey6619ae42021-08-06 11:21:10 -0700129 getSensorConnection(ipmi::Context::ptr ctx, uint8_t sensnum,
Hao Jiange39d4d82021-04-16 17:02:40 -0700130 std::string& connection, std::string& path,
131 std::vector<std::string>* interfaces = nullptr)
Willy Tude54f482021-01-26 15:59:09 -0800132{
133 auto& sensorTree = getSensorTree();
Kuiying Wanga8b5b262021-02-06 23:38:22 +0800134 if (!getSensorSubtree(sensorTree) && sensorTree.empty())
Willy Tude54f482021-01-26 15:59:09 -0800135 {
136 return IPMI_CC_RESPONSE_ERROR;
137 }
138
139 if (ctx == nullptr)
140 {
141 return IPMI_CC_RESPONSE_ERROR;
142 }
143
144 path = getPathFromSensorNumber((ctx->lun << 8) | sensnum);
145 if (path.empty())
146 {
147 return IPMI_CC_INVALID_FIELD_REQUEST;
148 }
149
150 for (const auto& sensor : sensorTree)
151 {
152 if (path == sensor.first)
153 {
154 connection = sensor.second.begin()->first;
Hao Jiange39d4d82021-04-16 17:02:40 -0700155 if (interfaces)
156 *interfaces = sensor.second.begin()->second;
Willy Tude54f482021-01-26 15:59:09 -0800157 break;
158 }
159 }
160
161 return 0;
162}
163
164struct IPMIThresholds
165{
166 std::optional<uint8_t> warningLow;
167 std::optional<uint8_t> warningHigh;
168 std::optional<uint8_t> criticalLow;
169 std::optional<uint8_t> criticalHigh;
170};
171
Thang Tranb1416ef2023-08-02 13:57:09 +0700172namespace dcmi
173{
174
175struct sensorInfo
176{
177 std::string objectPath;
178 uint8_t type;
179 uint16_t recordId;
180 uint8_t entityId;
181 uint8_t entityInstance;
182};
183
184} // namespace dcmi
185
Willy Tude54f482021-01-26 15:59:09 -0800186} // namespace ipmi