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, |
Johnathan Mantey | 7b03727 | 2024-06-17 12:12:40 -0700 | [diff] [blame] | 63 | joules = 0x7, |
Willy Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 64 | rpm = 0x12, |
| 65 | }; |
| 66 | |
| 67 | #pragma pack(push, 1) |
| 68 | struct 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) |
| 82 | struct Type12Record |
| 83 | { |
| 84 | get_sdr::SensorDataRecordHeader header; |
Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 85 | uint8_t targetAddress; |
Willy Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 86 | uint8_t channelNumber; |
| 87 | uint8_t powerStateNotification; |
| 88 | uint8_t deviceCapabilities; |
Johnathan Mantey | cd1c496 | 2021-09-22 12:58:08 -0700 | [diff] [blame] | 89 | // 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 Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 92 | uint8_t entityID; |
| 93 | uint8_t entityInstance; |
| 94 | uint8_t oem; |
| 95 | uint8_t typeLengthCode; |
| 96 | char name[16]; |
Johnathan Mantey | cd1c496 | 2021-09-22 12:58:08 -0700 | [diff] [blame] | 97 | |
| 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 Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 102 | targetAddress(address), |
Johnathan Mantey | cd1c496 | 2021-09-22 12:58:08 -0700 | [diff] [blame] | 103 | 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 Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 117 | }; |
| 118 | #pragma pack(pop) |
| 119 | |
| 120 | namespace ipmi |
| 121 | { |
| 122 | namespace storage |
| 123 | { |
| 124 | |
| 125 | constexpr const size_t type12Count = 2; |
| 126 | ipmi_ret_t getFruSdrs(ipmi::Context::ptr ctx, size_t index, |
| 127 | get_sdr::SensorDataFruRecord& resp); |
| 128 | |
| 129 | ipmi_ret_t getFruSdrCount(ipmi::Context::ptr ctx, size_t& count); |
| 130 | |
Harvey Wu | 05d17c0 | 2021-09-15 08:46:59 +0800 | [diff] [blame] | 131 | std::vector<uint8_t> |
| 132 | getType8SDRs(ipmi::sensor::EntityInfoMap::const_iterator& entity, |
| 133 | uint16_t recordId); |
Willy Tu | de54f48 | 2021-01-26 15:59:09 -0800 | [diff] [blame] | 134 | std::vector<uint8_t> getType12SDRs(uint16_t index, uint16_t recordId); |
| 135 | std::vector<uint8_t> getNMDiscoverySDR(uint16_t index, uint16_t recordId); |
| 136 | } // namespace storage |
| 137 | } // namespace ipmi |