1de54f486SWilly Tu /* 2de54f486SWilly Tu // Copyright (c) 2017 2018 Intel Corporation 3de54f486SWilly Tu // 4de54f486SWilly Tu // Licensed under the Apache License, Version 2.0 (the "License"); 5de54f486SWilly Tu // you may not use this file except in compliance with the License. 6de54f486SWilly Tu // You may obtain a copy of the License at 7de54f486SWilly Tu // 8de54f486SWilly Tu // http://www.apache.org/licenses/LICENSE-2.0 9de54f486SWilly Tu // 10de54f486SWilly Tu // Unless required by applicable law or agreed to in writing, software 11de54f486SWilly Tu // distributed under the License is distributed on an "AS IS" BASIS, 12de54f486SWilly Tu // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13de54f486SWilly Tu // See the License for the specific language governing permissions and 14de54f486SWilly Tu // limitations under the License. 15de54f486SWilly Tu */ 16de54f486SWilly Tu 17de54f486SWilly Tu #pragma once 18de54f486SWilly Tu #include "sensorhandler.hpp" 19de54f486SWilly Tu 20de54f486SWilly Tu #include <cstdint> 21de54f486SWilly Tu 22de54f486SWilly Tu static constexpr uint8_t ipmiSdrVersion = 0x51; 23de54f486SWilly Tu 24de54f486SWilly Tu namespace dynamic_sensors::ipmi::sel 25de54f486SWilly Tu { 26de54f486SWilly Tu static constexpr uint8_t selOperationSupport = 0x02; 27de54f486SWilly Tu static constexpr uint8_t systemEvent = 0x02; 28de54f486SWilly Tu static constexpr size_t systemEventSize = 3; 29de54f486SWilly Tu static constexpr uint8_t oemTsEventFirst = 0xC0; 30de54f486SWilly Tu static constexpr uint8_t oemTsEventLast = 0xDF; 31de54f486SWilly Tu static constexpr size_t oemTsEventSize = 9; 32de54f486SWilly Tu static constexpr uint8_t oemEventFirst = 0xE0; 33de54f486SWilly Tu static constexpr uint8_t oemEventLast = 0xFF; 34de54f486SWilly Tu static constexpr size_t oemEventSize = 13; 35de54f486SWilly Tu static constexpr uint8_t eventMsgRev = 0x04; 36de54f486SWilly Tu } // namespace dynamic_sensors::ipmi::sel 37de54f486SWilly Tu 38de54f486SWilly Tu enum class SdrRepositoryInfoOps : uint8_t 39de54f486SWilly Tu { 40de54f486SWilly Tu allocCommandSupported = 0x1, 41de54f486SWilly Tu reserveSDRRepositoryCommandSupported = 0x2, 42de54f486SWilly Tu partialAddSDRSupported = 0x4, 43de54f486SWilly Tu deleteSDRSupported = 0x8, 44de54f486SWilly Tu reserved = 0x10, 45de54f486SWilly Tu modalLSB = 0x20, 46de54f486SWilly Tu modalMSB = 0x40, 47de54f486SWilly Tu overflow = 0x80 48de54f486SWilly Tu }; 49de54f486SWilly Tu 50de54f486SWilly Tu enum class GetFRUAreaAccessType : uint8_t 51de54f486SWilly Tu { 52de54f486SWilly Tu byte = 0x0, 53de54f486SWilly Tu words = 0x1 54de54f486SWilly Tu }; 55de54f486SWilly Tu 56de54f486SWilly Tu enum class SensorUnits : uint8_t 57de54f486SWilly Tu { 58de54f486SWilly Tu unspecified = 0x0, 59de54f486SWilly Tu degreesC = 0x1, 60de54f486SWilly Tu volts = 0x4, 61de54f486SWilly Tu amps = 0x5, 62de54f486SWilly Tu watts = 0x6, 637b037276SJohnathan Mantey joules = 0x7, 64de54f486SWilly Tu rpm = 0x12, 65de54f486SWilly Tu }; 66de54f486SWilly Tu 67de54f486SWilly Tu #pragma pack(push, 1) 68de54f486SWilly Tu struct FRUHeader 69de54f486SWilly Tu { 70de54f486SWilly Tu uint8_t commonHeaderFormat; 71de54f486SWilly Tu uint8_t internalOffset; 72de54f486SWilly Tu uint8_t chassisOffset; 73de54f486SWilly Tu uint8_t boardOffset; 74de54f486SWilly Tu uint8_t productOffset; 75de54f486SWilly Tu uint8_t multiRecordOffset; 76de54f486SWilly Tu uint8_t pad; 77de54f486SWilly Tu uint8_t checksum; 78de54f486SWilly Tu }; 79de54f486SWilly Tu #pragma pack(pop) 80de54f486SWilly Tu 81de54f486SWilly Tu #pragma pack(push, 1) 82de54f486SWilly Tu struct Type12Record 83de54f486SWilly Tu { 84de54f486SWilly Tu get_sdr::SensorDataRecordHeader header; 8568d9d405SMatt Simmering uint8_t targetAddress; 86de54f486SWilly Tu uint8_t channelNumber; 87de54f486SWilly Tu uint8_t powerStateNotification; 88de54f486SWilly Tu uint8_t deviceCapabilities; 89cd1c4963SJohnathan Mantey // define reserved bytes explicitly. The uint24_t is silently expanded to 90cd1c4963SJohnathan Mantey // uint32_t, which ruins the byte alignment required by this structure. 91cd1c4963SJohnathan Mantey uint8_t reserved[3]; 92de54f486SWilly Tu uint8_t entityID; 93de54f486SWilly Tu uint8_t entityInstance; 94de54f486SWilly Tu uint8_t oem; 95de54f486SWilly Tu uint8_t typeLengthCode; 96de54f486SWilly Tu char name[16]; 97cd1c4963SJohnathan Mantey Type12RecordType12Record98cd1c4963SJohnathan Mantey Type12Record(uint16_t recordID, uint8_t address, uint8_t chNumber, 99cd1c4963SJohnathan Mantey uint8_t pwrStateNotification, uint8_t capabilities, 100cd1c4963SJohnathan Mantey uint8_t eid, uint8_t entityInst, uint8_t mfrDefined, 101cd1c4963SJohnathan Mantey const std::string& sensorname) : 102*1318a5edSPatrick Williams targetAddress(address), channelNumber(chNumber), 103*1318a5edSPatrick Williams powerStateNotification(pwrStateNotification), 104cd1c4963SJohnathan Mantey deviceCapabilities(capabilities), reserved{}, entityID(eid), 105cd1c4963SJohnathan Mantey entityInstance(entityInst), oem(mfrDefined) 106cd1c4963SJohnathan Mantey { 107cd1c4963SJohnathan Mantey get_sdr::header::set_record_id(recordID, &header); 108cd1c4963SJohnathan Mantey header.sdr_version = ipmiSdrVersion; 109cd1c4963SJohnathan Mantey header.record_type = 0x12; 110cd1c4963SJohnathan Mantey size_t nameLen = std::min(sensorname.size(), sizeof(name)); 111*1318a5edSPatrick Williams header.record_length = 112*1318a5edSPatrick Williams sizeof(Type12Record) - sizeof(get_sdr::SensorDataRecordHeader) - 113cd1c4963SJohnathan Mantey sizeof(name) + nameLen; 114cd1c4963SJohnathan Mantey typeLengthCode = 0xc0 | nameLen; 115cd1c4963SJohnathan Mantey std::copy(sensorname.begin(), sensorname.begin() + nameLen, name); 116cd1c4963SJohnathan Mantey } 117de54f486SWilly Tu }; 118de54f486SWilly Tu #pragma pack(pop) 119de54f486SWilly Tu 120de54f486SWilly Tu namespace ipmi 121de54f486SWilly Tu { 122de54f486SWilly Tu namespace storage 123de54f486SWilly Tu { 124de54f486SWilly Tu 125de54f486SWilly Tu constexpr const size_t type12Count = 2; 126de54f486SWilly Tu ipmi_ret_t getFruSdrs(ipmi::Context::ptr ctx, size_t index, 127de54f486SWilly Tu get_sdr::SensorDataFruRecord& resp); 128de54f486SWilly Tu 129de54f486SWilly Tu ipmi_ret_t getFruSdrCount(ipmi::Context::ptr ctx, size_t& count); 130de54f486SWilly Tu 131*1318a5edSPatrick Williams std::vector<uint8_t> getType8SDRs( 132*1318a5edSPatrick Williams ipmi::sensor::EntityInfoMap::const_iterator& entity, uint16_t recordId); 133de54f486SWilly Tu std::vector<uint8_t> getType12SDRs(uint16_t index, uint16_t recordId); 134de54f486SWilly Tu std::vector<uint8_t> getNMDiscoverySDR(uint16_t index, uint16_t recordId); 135de54f486SWilly Tu } // namespace storage 136de54f486SWilly Tu } // namespace ipmi 137