1 #pragma once 2 3 #include <cstdint> 4 #include <filesystem> 5 #include <iostream> 6 7 namespace openpower 8 { 9 namespace vpd 10 { 11 namespace constants 12 { 13 14 using RecordId = uint8_t; 15 using RecordOffset = uint16_t; 16 using RecordSize = uint16_t; 17 using RecordType = uint16_t; 18 using RecordLength = uint16_t; 19 using KwSize = uint8_t; 20 using PoundKwSize = uint16_t; 21 using ECCOffset = uint16_t; 22 using ECCLength = uint16_t; 23 using LE2ByteData = uint16_t; 24 using DataOffset = uint16_t; 25 26 static constexpr auto NEXT_64_KB = 65536; 27 static constexpr auto MAC_ADDRESS_LEN_BYTES = 6; 28 static constexpr auto LAST_KW = "PF"; 29 static constexpr auto POUND_KW = '#'; 30 static constexpr auto POUND_KW_PREFIX = "PD_"; 31 static constexpr auto NUMERIC_KW_PREFIX = "N_"; 32 static constexpr auto UUID_LEN_BYTES = 16; 33 static constexpr auto UUID_TIME_LOW_END = 8; 34 static constexpr auto UUID_TIME_MID_END = 13; 35 static constexpr auto UUID_TIME_HIGH_END = 18; 36 static constexpr auto UUID_CLK_SEQ_END = 23; 37 38 static constexpr auto MB_RESULT_LEN = 19; 39 static constexpr auto MB_LEN_BYTES = 8; 40 static constexpr auto MB_YEAR_END = 4; 41 static constexpr auto MB_MONTH_END = 7; 42 static constexpr auto MB_DAY_END = 10; 43 static constexpr auto MB_HOUR_END = 13; 44 static constexpr auto MB_MIN_END = 16; 45 static constexpr auto SYSTEM_OBJECT = "/system/chassis/motherboard"; 46 static constexpr auto IBM_LOCATION_CODE_INF = "com.ibm.ipzvpd.Location"; 47 static constexpr auto XYZ_LOCATION_CODE_INF = 48 "xyz.openbmc_project.Inventory.Decorator.LocationCode"; 49 constexpr int IPZ_DATA_START = 11; 50 constexpr uint8_t KW_VAL_PAIR_START_TAG = 0x84; 51 constexpr uint8_t RECORD_END_TAG = 0x78; 52 constexpr int UNEXP_LOCATION_CODE_MIN_LENGTH = 4; 53 constexpr uint8_t EXP_LOCATIN_CODE_MIN_LENGTH = 17; 54 static constexpr auto SE_KWD_LENGTH = 7; 55 static constexpr auto INVALID_NODE_NUMBER = -1; 56 static constexpr auto RAINIER_2U = "50001001.json"; 57 static constexpr auto RAINIER_2U_V2 = "50001001_v2.json"; 58 static constexpr auto RAINIER_4U = "50001000.json"; 59 static constexpr auto RAINIER_4U_V2 = "50001000_v2.json"; 60 static constexpr auto RAINIER_1S4U = "50001002.json"; 61 static constexpr auto EVEREST = "50003000.json"; 62 static constexpr auto EVEREST_V2 = "50003000_v2.json"; 63 static constexpr auto BONNELL = "50004000.json"; 64 65 constexpr uint8_t KW_VPD_START_TAG = 0x82; 66 constexpr uint8_t KW_VPD_END_TAG = 0x78; 67 constexpr uint8_t ALT_KW_VAL_PAIR_START_TAG = 0x90; 68 constexpr uint8_t KW_VAL_PAIR_END_TAG = 0x79; 69 constexpr auto MEMORY_VPD_START_TAG = "11S"; 70 constexpr int TWO_BYTES = 2; 71 constexpr int KW_VPD_DATA_START = 0; 72 constexpr auto MEMORY_VPD_DATA_START = 416; 73 constexpr auto FORMAT_11S_LEN = 3; 74 static constexpr auto PART_NUM_LEN = 7; 75 static constexpr auto SERIAL_NUM_LEN = 12; 76 static constexpr auto CCIN_LEN = 4; 77 static constexpr auto CONVERT_MB_TO_KB = 1024; 78 static constexpr auto CONVERT_GB_TO_KB = 1024 * 1024; 79 80 static constexpr auto SPD_BYTE_2 = 2; 81 static constexpr auto SPD_BYTE_3 = 3; 82 static constexpr auto SPD_BYTE_4 = 4; 83 static constexpr auto SPD_BYTE_6 = 6; 84 static constexpr auto SPD_BYTE_12 = 12; 85 static constexpr auto SPD_BYTE_13 = 13; 86 static constexpr auto SPD_BYTE_18 = 18; 87 static constexpr auto SPD_BYTE_234 = 234; 88 static constexpr auto SPD_BYTE_235 = 235; 89 static constexpr auto SPD_BYTE_BIT_0_3_MASK = 0x0F; 90 static constexpr auto SPD_BYTE_MASK = 0xFF; 91 92 static constexpr auto VALUE_0 = 0; 93 static constexpr auto VALUE_1 = 1; 94 static constexpr auto VALUE_2 = 2; 95 static constexpr auto VALUE_3 = 3; 96 static constexpr auto VALUE_4 = 4; 97 static constexpr auto VALUE_5 = 5; 98 static constexpr auto VALUE_6 = 6; 99 static constexpr auto VALUE_7 = 7; 100 static constexpr auto VALUE_8 = 8; 101 102 static constexpr auto MASK_BYTE_BITS_6 = 0x40; 103 static constexpr auto MASK_BYTE_BITS_7 = 0x80; 104 static constexpr auto MASK_BYTE_BITS_01 = 0x03; 105 static constexpr auto MASK_BYTE_BITS_345 = 0x38; 106 static constexpr auto MASK_BYTE_BITS_012 = 0x07; 107 static constexpr auto MASK_BYTE_BITS_567 = 0xE0; 108 static constexpr auto MASK_BYTE_BITS_0123 = 0x0F; 109 static constexpr auto MASK_BYTE_BITS_01234 = 0x1F; 110 111 static constexpr auto SHIFT_BITS_0 = 0; 112 static constexpr auto SHIFT_BITS_3 = 3; 113 static constexpr auto SHIFT_BITS_5 = 5; 114 115 static constexpr auto SPD_MODULE_TYPE_DDIMM = 0x0A; 116 static constexpr auto SPD_DRAM_TYPE_DDR5 = 0x12; 117 static constexpr auto SPD_DRAM_TYPE_DDR4 = 0x0C; 118 119 constexpr auto pimPath = "/xyz/openbmc_project/inventory"; 120 constexpr auto pimIntf = "xyz.openbmc_project.Inventory.Manager"; 121 constexpr auto pimService = "xyz.openbmc_project.Inventory.Manager"; 122 constexpr auto kwdVpdInf = "com.ibm.ipzvpd.VINI"; 123 constexpr auto memVpdInf = "com.ibm.ipzvpd.VINI"; 124 constexpr auto ipzVpdInf = "com.ibm.ipzvpd."; 125 constexpr auto offsetJsonDirectory = "/var/lib/vpd/"; 126 constexpr auto mapperObjectPath = "/xyz/openbmc_project/object_mapper"; 127 constexpr auto mapperInterface = "xyz.openbmc_project.ObjectMapper"; 128 constexpr auto mapperDestination = "xyz.openbmc_project.ObjectMapper"; 129 constexpr auto loggerService = "xyz.openbmc_project.Logging"; 130 constexpr auto loggerObjectPath = "/xyz/openbmc_project/logging"; 131 constexpr auto loggerCreateInterface = "xyz.openbmc_project.Logging.Create"; 132 constexpr auto errIntfForVPDDefault = "com.ibm.VPD.Error.DefaultValue"; 133 constexpr auto errIntfForInvalidVPD = "com.ibm.VPD.Error.InvalidVPD"; 134 constexpr auto errIntfForVPDMismatch = "com.ibm.VPD.Error.Mismatch"; 135 constexpr auto errIntfForStreamFail = "com.ibm.VPD.Error.InvalidEepromPath"; 136 constexpr auto errIntfForEccCheckFail = "com.ibm.VPD.Error.EccCheckFailed"; 137 constexpr auto errIntfForJsonFailure = "com.ibm.VPD.Error.InvalidJson"; 138 constexpr auto errIntfForBusFailure = "com.ibm.VPD.Error.DbusFailure"; 139 constexpr auto errIntfForInvalidSystemType = 140 "com.ibm.VPD.Error.UnknownSytemType"; 141 constexpr auto errIntfForEssentialFru = "com.ibm.VPD.Error.RequiredFRUMissing"; 142 constexpr auto errIntfForGpioError = "com.ibm.VPD.Error.GPIOError"; 143 constexpr auto motherBoardInterface = 144 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"; 145 constexpr auto systemVpdFilePath = "/sys/bus/i2c/drivers/at24/8-0050/eeprom"; 146 constexpr auto i2cPathPrefix = "/sys/bus/i2c/drivers/"; 147 constexpr auto spiPathPrefix = "/sys/bus/spi/drivers/"; 148 constexpr auto at24driver = "at24"; 149 constexpr auto at25driver = "at25"; 150 constexpr auto ee1004driver = "ee1004"; 151 constexpr auto invItemIntf = "xyz.openbmc_project.Inventory.Item"; 152 constexpr auto invAssetIntf = "xyz.openbmc_project.Inventory.Decorator.Asset"; 153 constexpr auto invOperationalStatusIntf = 154 "xyz.openbmc_project.State.Decorator.OperationalStatus"; 155 static constexpr std::uintmax_t MAX_VPD_SIZE = 65504; 156 157 namespace lengths 158 { 159 enum Lengths 160 { 161 RECORD_NAME = 4, 162 KW_NAME = 2, 163 RECORD_OFFSET = 2, 164 RECORD_MIN = 44, 165 RECORD_LENGTH = 2, 166 RECORD_ECC_OFFSET = 2, 167 VHDR_ECC_LENGTH = 11, 168 VHDR_RECORD_LENGTH = 44 169 }; // enum Lengths 170 } // namespace lengths 171 172 namespace offsets 173 { 174 enum Offsets 175 { 176 VHDR = 17, 177 VHDR_TOC_ENTRY = 29, 178 VTOC_PTR = 35, 179 VTOC_REC_LEN = 37, 180 VTOC_ECC_OFF = 39, 181 VTOC_ECC_LEN = 41, 182 VTOC_DATA = 13, 183 VHDR_ECC = 0, 184 VHDR_RECORD = 11 185 }; 186 } // namespace offsets 187 188 namespace eccStatus 189 { 190 enum Status 191 { 192 SUCCESS = 0, 193 FAILED = -1 194 }; 195 } // namespace eccStatus 196 197 /** 198 * @brief Types of VPD 199 */ 200 enum vpdType 201 { 202 IPZ_VPD, /**< IPZ VPD type */ 203 KEYWORD_VPD, /**< Keyword VPD type */ 204 DDR4_DDIMM_MEMORY_VPD, /**< DDR4 DDIMM Memory VPD type */ 205 DDR5_DDIMM_MEMORY_VPD, /**< DDR5 DDIMM Memory VPD type */ 206 DDR4_ISDIMM_MEMORY_VPD, /**< DDR4 ISDIMM Memory VPD type */ 207 DDR5_ISDIMM_MEMORY_VPD, /**< DDR5 ISDIMM Memory VPD type */ 208 INVALID_VPD_FORMAT /**< Invalid VPD type Format */ 209 }; 210 211 enum PelSeverity 212 { 213 NOTICE, 214 INFORMATIONAL, 215 DEBUG, 216 WARNING, 217 CRITICAL, 218 EMERGENCY, 219 ALERT, 220 ERROR 221 }; 222 223 } // namespace constants 224 } // namespace vpd 225 } // namespace openpower 226