1 /* 2 * Copyright (c) 2018-present Facebook. All Rights Reserved. 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 "sdrutils.hpp" 19 20 #define SEL_JSON_DATA_FILE "/var/log/fbSelRaw.json" 21 #define KEY_SEL_COUNT "SelCount" 22 #define KEY_SEL_ENTRY_RAW "SelEntry" 23 #define KEY_ADD_TIME "AddTimeStamp" 24 #define KEY_ERASE_TIME "EraseTimeStamp" 25 #define KEY_FREE_SPACE "FreeSpace" 26 #define KEY_OPER_SUPP "OperationalSupport" 27 #define KEY_SEL_VER "SELVersion" 28 #define BIT(value, index) ((value >> index) & 1) 29 30 static constexpr uint8_t ipmiSdrVersion = 0x51; 31 32 #pragma pack(push, 1) 33 34 struct GetSDRReq 35 { 36 uint16_t reservationID; 37 uint16_t recordID; 38 uint8_t offset; 39 uint8_t bytesToRead; 40 }; 41 42 struct GetFRUAreaResp 43 { 44 uint8_t inventorySizeLSB; 45 uint8_t inventorySizeMSB; 46 uint8_t accessType; 47 }; 48 49 struct GetFRUAreaReq 50 { 51 uint8_t fruDeviceID; 52 uint16_t fruInventoryOffset; 53 uint8_t countToRead; 54 }; 55 56 struct WriteFRUDataReq 57 { 58 uint8_t fruDeviceID; 59 uint16_t fruInventoryOffset; 60 uint8_t data[]; 61 }; 62 63 #pragma pack(pop) 64 65 enum class GetFRUAreaAccessType : uint8_t 66 { 67 byte = 0x0, 68 words = 0x1 69 }; 70 71 enum class IPMINetfnStorageCmds : ipmi_cmd_t 72 { 73 ipmiCmdGetFRUInvAreaInfo = 0x10, 74 ipmiCmdReadFRUData = 0x11, 75 ipmiCmdWriteFRUData = 0x12, 76 ipmiCmdGetRepositoryInfo = 0x20, 77 ipmiCmdGetSDRAllocationInfo = 0x21, 78 ipmiCmdReserveSDR = 0x22, 79 ipmiCmdGetSDR = 0x23, 80 ipmiCmdGetSELInfo = 0x40, 81 ipmiCmdReserveSEL = 0x42, 82 ipmiCmdGetSELEntry = 0x43, 83 ipmiCmdAddSEL = 0x44, 84 ipmiCmdDeleteSEL = 0x46, 85 ipmiCmdClearSEL = 0x47, 86 ipmiCmdGetSELTime = 0x48, 87 ipmiCmdSetSELTime = 0x49, 88 }; 89 90 #pragma pack(push, 1) 91 struct FRUHeader 92 { 93 uint8_t commonHeaderFormat; 94 uint8_t internalOffset; 95 uint8_t chassisOffset; 96 uint8_t boardOffset; 97 uint8_t productOffset; 98 uint8_t multiRecordOffset; 99 uint8_t pad; 100 uint8_t checksum; 101 }; 102 #pragma pack(pop) 103 104 namespace fb_oem::ipmi::sel 105 { 106 107 static constexpr auto selVersion = 0x51; 108 static constexpr auto invalidTimeStamp = 0xFFFFFFFF; 109 /* Spec indicates that more than 64kB is free */ 110 static constexpr auto freeSpace = 0xFFFF; 111 static constexpr uint8_t selOperationSupport = 0x02; 112 113 static constexpr auto firstEntry = 0x0000; 114 static constexpr auto lastEntry = 0xFFFF; 115 static constexpr auto entireRecord = 0xFF; 116 static constexpr auto selRecordSize = 16; 117 118 static constexpr auto stdErr = "Standard"; 119 static constexpr auto oemTSErr = "OEM timestamped"; 120 static constexpr auto fbUniSELErr = "Facebook Unified SEL"; 121 static constexpr auto oemNTSErr = "OEM non-timestamped"; 122 static constexpr auto unknownErr = "Unknown"; 123 124 static constexpr uint8_t stdErrType = 0x02; 125 static constexpr uint8_t oemTSErrTypeMin = 0xC0; 126 static constexpr uint8_t oemTSErrTypeMax = 0xDF; 127 static constexpr uint8_t oemNTSErrTypeMin = 0xE0; 128 static constexpr uint8_t fbUniErrType = 0xFB; 129 static constexpr uint8_t oemNTSErrTypeMax = 0xFF; 130 131 static constexpr uint8_t unifiedPcieErr = 0; 132 static constexpr uint8_t unifiedMemErr = 1; 133 134 /* event sensor name in processing SEL */ 135 static constexpr uint8_t memoryEccError = 0x63; 136 static constexpr uint8_t memoryErrLogDIS = 0x87; 137 138 /** @struct GetSELInfoData 139 * 140 * IPMI response payload data for Get SEL Info request 141 */ 142 struct GetSELInfoData 143 { 144 uint8_t selVersion; 145 uint16_t entries; 146 uint16_t freeSpace; 147 uint32_t addTimeStamp; 148 uint32_t eraseTimeStamp; 149 uint8_t operationSupport; 150 }; 151 152 /** @struct GetSELEntryRequest 153 * 154 * IPMI payload for Get SEL Entry command request. 155 */ 156 struct GetSELEntryRequest 157 { 158 uint16_t reservID; //!< Reservation ID. 159 uint16_t recordID; //!< SEL Record ID. 160 uint8_t offset; //!< Offset into record. 161 uint8_t readLen; //!< Bytes to read. 162 } __attribute__((packed)); 163 164 /** @struct GetSELEntryResponse 165 * 166 * IPMI payload for Get SEL Entry command response. 167 */ 168 struct GetSELEntryResponse 169 { 170 uint16_t nextRecordID; //!< Next RecordID. 171 uint8_t recordData[16]; //!< Record Data. 172 } __attribute__((packed)); 173 174 /** @struct AddSELEntryRequest 175 * 176 * IPMI payload for ADD SEL Entry command request. 177 */ 178 struct StdSELEntry 179 { 180 uint16_t recordID; //!< Record ID. 181 uint8_t recordType; //!< Record Type. 182 uint32_t timeStamp; //!< Timestamp. 183 uint16_t generatorID; //!< Generator ID. 184 uint8_t eventMsgRevision; //!< Event Message Revision. 185 uint8_t sensorType; //!< Sensor Type. 186 uint8_t sensorNum; //!< Sensor Number. 187 uint8_t eventType; //!< Event Dir | Event Type. 188 uint8_t eventData1; //!< Event Data 1. 189 uint8_t eventData2; //!< Event Data 2. 190 uint8_t eventData3; //!< Event Data 3. 191 } __attribute__((packed)); 192 193 struct TsOemSELEntry 194 { 195 uint16_t recordID; //!< Record ID. 196 uint8_t recordType; //!< Record Type. 197 uint32_t timeStamp; //!< Timestamp. 198 uint8_t mfrId[3]; //!< Manufacturer Id. 199 uint8_t oemData[6]; //!< OEM Data. 200 } __attribute__((packed)); 201 202 struct NtsOemSELEntry 203 { 204 uint16_t recordID; //!< Record ID. 205 uint8_t recordType; //!< Record Type. 206 uint8_t oemData[13]; //!< OEM Data. 207 } __attribute__((packed)); 208 209 static constexpr auto initiateErase = 0xAA; 210 static constexpr auto getEraseStatus = 0x00; 211 static constexpr auto eraseComplete = 0x01; 212 213 } // namespace fb_oem::ipmi::sel 214