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