Willy Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 1 | /* |
| 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 Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 22 | static constexpr uint8_t ipmiSdrVersion = 0x51; |
| 23 | |
| 24 | namespace dynamic_sensors::ipmi::sel |
| 25 | { |
| 26 | static constexpr uint8_t selOperationSupport = 0x02; |
| 27 | static constexpr uint8_t systemEvent = 0x02; |
| 28 | static constexpr size_t systemEventSize = 3; |
| 29 | static constexpr uint8_t oemTsEventFirst = 0xC0; |
| 30 | static constexpr uint8_t oemTsEventLast = 0xDF; |
| 31 | static constexpr size_t oemTsEventSize = 9; |
| 32 | static constexpr uint8_t oemEventFirst = 0xE0; |
| 33 | static constexpr uint8_t oemEventLast = 0xFF; |
| 34 | static constexpr size_t oemEventSize = 13; |
| 35 | static constexpr uint8_t eventMsgRev = 0x04; |
| 36 | } // namespace dynamic_sensors::ipmi::sel |
| 37 | |
| 38 | enum 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 | |
| 50 | enum class GetFRUAreaAccessType : uint8_t |
| 51 | { |
| 52 | byte = 0x0, |
| 53 | words = 0x1 |
| 54 | }; |
| 55 | |
| 56 | enum 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) |
| 67 | struct 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) |
| 81 | struct Type12Record |
| 82 | { |
| 83 | get_sdr::SensorDataRecordHeader header; |
Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 84 | uint8_t targetAddress; |
Willy Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 85 | uint8_t channelNumber; |
| 86 | uint8_t powerStateNotification; |
| 87 | uint8_t deviceCapabilities; |
Johnathan Mantey | cd1c496 | 2021-09-22 12:58:08 -0700 | [diff] [blame] | 88 | // 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 Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 91 | uint8_t entityID; |
| 92 | uint8_t entityInstance; |
| 93 | uint8_t oem; |
| 94 | uint8_t typeLengthCode; |
| 95 | char name[16]; |
Johnathan Mantey | cd1c496 | 2021-09-22 12:58:08 -0700 | [diff] [blame] | 96 | |
| 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 Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 101 | targetAddress(address), |
Johnathan Mantey | cd1c496 | 2021-09-22 12:58:08 -0700 | [diff] [blame] | 102 | 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 Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 116 | }; |
| 117 | #pragma pack(pop) |
| 118 | |
| 119 | namespace ipmi |
| 120 | { |
| 121 | namespace storage |
| 122 | { |
| 123 | |
| 124 | constexpr const size_t type12Count = 2; |
| 125 | ipmi_ret_t getFruSdrs(ipmi::Context::ptr ctx, size_t index, |
| 126 | get_sdr::SensorDataFruRecord& resp); |
| 127 | |
| 128 | ipmi_ret_t getFruSdrCount(ipmi::Context::ptr ctx, size_t& count); |
| 129 | |
Harvey Wu | 05d17c0 | 2021-09-15 08:46:59 +0800 | [diff] [blame] | 130 | std::vector<uint8_t> |
| 131 | getType8SDRs(ipmi::sensor::EntityInfoMap::const_iterator& entity, |
| 132 | uint16_t recordId); |
Willy Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 133 | std::vector<uint8_t> getType12SDRs(uint16_t index, uint16_t recordId); |
| 134 | std::vector<uint8_t> getNMDiscoverySDR(uint16_t index, uint16_t recordId); |
| 135 | } // namespace storage |
| 136 | } // namespace ipmi |