blob: 2ae9291f0c1b71912771da58d1ac3df51094bd5d [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
18#include "sensorhandler.hpp"
19
20#include <cstdint>
21
Willy Tude54f482021-01-26 15:59:09 -080022static constexpr uint8_t ipmiSdrVersion = 0x51;
23
24namespace dynamic_sensors::ipmi::sel
25{
26static constexpr uint8_t selOperationSupport = 0x02;
27static constexpr uint8_t systemEvent = 0x02;
28static constexpr size_t systemEventSize = 3;
29static constexpr uint8_t oemTsEventFirst = 0xC0;
30static constexpr uint8_t oemTsEventLast = 0xDF;
31static constexpr size_t oemTsEventSize = 9;
32static constexpr uint8_t oemEventFirst = 0xE0;
33static constexpr uint8_t oemEventLast = 0xFF;
34static constexpr size_t oemEventSize = 13;
35static constexpr uint8_t eventMsgRev = 0x04;
36} // namespace dynamic_sensors::ipmi::sel
37
38enum class SdrRepositoryInfoOps : uint8_t
39{
40 allocCommandSupported = 0x1,
41 reserveSDRRepositoryCommandSupported = 0x2,
42 partialAddSDRSupported = 0x4,
43 deleteSDRSupported = 0x8,
44 reserved = 0x10,
45 modalLSB = 0x20,
46 modalMSB = 0x40,
47 overflow = 0x80
48};
49
50enum class GetFRUAreaAccessType : uint8_t
51{
52 byte = 0x0,
53 words = 0x1
54};
55
56enum class SensorUnits : uint8_t
57{
58 unspecified = 0x0,
59 degreesC = 0x1,
60 volts = 0x4,
61 amps = 0x5,
62 watts = 0x6,
Johnathan Mantey7b037272024-06-17 12:12:40 -070063 joules = 0x7,
Willy Tude54f482021-01-26 15:59:09 -080064 rpm = 0x12,
65};
66
67#pragma pack(push, 1)
68struct FRUHeader
69{
70 uint8_t commonHeaderFormat;
71 uint8_t internalOffset;
72 uint8_t chassisOffset;
73 uint8_t boardOffset;
74 uint8_t productOffset;
75 uint8_t multiRecordOffset;
76 uint8_t pad;
77 uint8_t checksum;
78};
79#pragma pack(pop)
80
81#pragma pack(push, 1)
82struct Type12Record
83{
84 get_sdr::SensorDataRecordHeader header;
Matt Simmering68d9d402023-11-09 14:22:11 -080085 uint8_t targetAddress;
Willy Tude54f482021-01-26 15:59:09 -080086 uint8_t channelNumber;
87 uint8_t powerStateNotification;
88 uint8_t deviceCapabilities;
Johnathan Manteycd1c4962021-09-22 12:58:08 -070089 // define reserved bytes explicitly. The uint24_t is silently expanded to
90 // uint32_t, which ruins the byte alignment required by this structure.
91 uint8_t reserved[3];
Willy Tude54f482021-01-26 15:59:09 -080092 uint8_t entityID;
93 uint8_t entityInstance;
94 uint8_t oem;
95 uint8_t typeLengthCode;
96 char name[16];
Johnathan Manteycd1c4962021-09-22 12:58:08 -070097
98 Type12Record(uint16_t recordID, uint8_t address, uint8_t chNumber,
99 uint8_t pwrStateNotification, uint8_t capabilities,
100 uint8_t eid, uint8_t entityInst, uint8_t mfrDefined,
101 const std::string& sensorname) :
Matt Simmering68d9d402023-11-09 14:22:11 -0800102 targetAddress(address),
Johnathan Manteycd1c4962021-09-22 12:58:08 -0700103 channelNumber(chNumber), powerStateNotification(pwrStateNotification),
104 deviceCapabilities(capabilities), reserved{}, entityID(eid),
105 entityInstance(entityInst), oem(mfrDefined)
106 {
107 get_sdr::header::set_record_id(recordID, &header);
108 header.sdr_version = ipmiSdrVersion;
109 header.record_type = 0x12;
110 size_t nameLen = std::min(sensorname.size(), sizeof(name));
111 header.record_length = sizeof(Type12Record) -
112 sizeof(get_sdr::SensorDataRecordHeader) -
113 sizeof(name) + nameLen;
114 typeLengthCode = 0xc0 | nameLen;
115 std::copy(sensorname.begin(), sensorname.begin() + nameLen, name);
116 }
Willy Tude54f482021-01-26 15:59:09 -0800117};
118#pragma pack(pop)
119
120namespace ipmi
121{
122namespace storage
123{
124
125constexpr const size_t type12Count = 2;
126ipmi_ret_t getFruSdrs(ipmi::Context::ptr ctx, size_t index,
127 get_sdr::SensorDataFruRecord& resp);
128
129ipmi_ret_t getFruSdrCount(ipmi::Context::ptr ctx, size_t& count);
130
Harvey Wu05d17c02021-09-15 08:46:59 +0800131std::vector<uint8_t>
132 getType8SDRs(ipmi::sensor::EntityInfoMap::const_iterator& entity,
133 uint16_t recordId);
Willy Tude54f482021-01-26 15:59:09 -0800134std::vector<uint8_t> getType12SDRs(uint16_t index, uint16_t recordId);
135std::vector<uint8_t> getNMDiscoverySDR(uint16_t index, uint16_t recordId);
136} // namespace storage
137} // namespace ipmi