blob: 7b3046c26bc1b1ce9dddc6ba2a39f7be49594d61 [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,
63 rpm = 0x12,
64};
65
66#pragma pack(push, 1)
67struct FRUHeader
68{
69 uint8_t commonHeaderFormat;
70 uint8_t internalOffset;
71 uint8_t chassisOffset;
72 uint8_t boardOffset;
73 uint8_t productOffset;
74 uint8_t multiRecordOffset;
75 uint8_t pad;
76 uint8_t checksum;
77};
78#pragma pack(pop)
79
80#pragma pack(push, 1)
81struct Type12Record
82{
83 get_sdr::SensorDataRecordHeader header;
Matt Simmering68d9d402023-11-09 14:22:11 -080084 uint8_t targetAddress;
Willy Tude54f482021-01-26 15:59:09 -080085 uint8_t channelNumber;
86 uint8_t powerStateNotification;
87 uint8_t deviceCapabilities;
Johnathan Manteycd1c4962021-09-22 12:58:08 -070088 // define reserved bytes explicitly. The uint24_t is silently expanded to
89 // uint32_t, which ruins the byte alignment required by this structure.
90 uint8_t reserved[3];
Willy Tude54f482021-01-26 15:59:09 -080091 uint8_t entityID;
92 uint8_t entityInstance;
93 uint8_t oem;
94 uint8_t typeLengthCode;
95 char name[16];
Johnathan Manteycd1c4962021-09-22 12:58:08 -070096
97 Type12Record(uint16_t recordID, uint8_t address, uint8_t chNumber,
98 uint8_t pwrStateNotification, uint8_t capabilities,
99 uint8_t eid, uint8_t entityInst, uint8_t mfrDefined,
100 const std::string& sensorname) :
Matt Simmering68d9d402023-11-09 14:22:11 -0800101 targetAddress(address),
Johnathan Manteycd1c4962021-09-22 12:58:08 -0700102 channelNumber(chNumber), powerStateNotification(pwrStateNotification),
103 deviceCapabilities(capabilities), reserved{}, entityID(eid),
104 entityInstance(entityInst), oem(mfrDefined)
105 {
106 get_sdr::header::set_record_id(recordID, &header);
107 header.sdr_version = ipmiSdrVersion;
108 header.record_type = 0x12;
109 size_t nameLen = std::min(sensorname.size(), sizeof(name));
110 header.record_length = sizeof(Type12Record) -
111 sizeof(get_sdr::SensorDataRecordHeader) -
112 sizeof(name) + nameLen;
113 typeLengthCode = 0xc0 | nameLen;
114 std::copy(sensorname.begin(), sensorname.begin() + nameLen, name);
115 }
Willy Tude54f482021-01-26 15:59:09 -0800116};
117#pragma pack(pop)
118
119namespace ipmi
120{
121namespace storage
122{
123
124constexpr const size_t type12Count = 2;
125ipmi_ret_t getFruSdrs(ipmi::Context::ptr ctx, size_t index,
126 get_sdr::SensorDataFruRecord& resp);
127
128ipmi_ret_t getFruSdrCount(ipmi::Context::ptr ctx, size_t& count);
129
Harvey Wu05d17c02021-09-15 08:46:59 +0800130std::vector<uint8_t>
131 getType8SDRs(ipmi::sensor::EntityInfoMap::const_iterator& entity,
132 uint16_t recordId);
Willy Tude54f482021-01-26 15:59:09 -0800133std::vector<uint8_t> getType12SDRs(uint16_t index, uint16_t recordId);
134std::vector<uint8_t> getNMDiscoverySDR(uint16_t index, uint16_t recordId);
135} // namespace storage
136} // namespace ipmi