1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * See file CREDITS for list of people who contributed to this
7 #ifndef __TLV_EEPROM_H_
8 #define __TLV_EEPROM_H_
11 * The Definition of the TlvInfo EEPROM format can be found at onie.org or
16 * TlvInfo header: Layout of the header for the TlvInfo format
18 * See the end of this file for details of this eeprom format
20 struct __attribute__ ((__packed__)) tlvinfo_header {
21 char signature[8]; /* 0x00 - 0x07 EEPROM Tag "TlvInfo" */
22 u8 version; /* 0x08 Structure version */
23 u16 totallen; /* 0x09 - 0x0A Length of all data which follows */
26 // Header Field Constants
27 #define TLV_INFO_ID_STRING "TlvInfo"
28 #define TLV_INFO_VERSION 0x01
29 #define TLV_INFO_MAX_LEN 2048
30 #define TLV_TOTAL_LEN_MAX (TLV_INFO_MAX_LEN - \
31 sizeof(struct tlvinfo_header))
34 * TlvInfo TLV: Layout of a TLV field
36 struct __attribute__ ((__packed__)) tlvinfo_tlv {
42 /* Maximum length of a TLV value in bytes */
43 #define TLV_VALUE_MAX_LEN 255
48 * Keep these in sync with tlv_code_list in cmd/tlv_eeprom.c
50 #define TLV_CODE_PRODUCT_NAME 0x21
51 #define TLV_CODE_PART_NUMBER 0x22
52 #define TLV_CODE_SERIAL_NUMBER 0x23
53 #define TLV_CODE_MAC_BASE 0x24
54 #define TLV_CODE_MANUF_DATE 0x25
55 #define TLV_CODE_DEVICE_VERSION 0x26
56 #define TLV_CODE_LABEL_REVISION 0x27
57 #define TLV_CODE_PLATFORM_NAME 0x28
58 #define TLV_CODE_ONIE_VERSION 0x29
59 #define TLV_CODE_MAC_SIZE 0x2A
60 #define TLV_CODE_MANUF_NAME 0x2B
61 #define TLV_CODE_MANUF_COUNTRY 0x2C
62 #define TLV_CODE_VENDOR_NAME 0x2D
63 #define TLV_CODE_DIAG_VERSION 0x2E
64 #define TLV_CODE_SERVICE_TAG 0x2F
65 #define TLV_CODE_VENDOR_EXT 0xFD
66 #define TLV_CODE_CRC_32 0xFE
68 #if CONFIG_IS_ENABLED(CMD_TLV_EEPROM)
71 * read_tlv_eeprom - Read the EEPROM binary data from the hardware
72 * @eeprom: Pointer to buffer to hold the binary data
73 * @offset: Offset within EEPROM block to read data from
74 * @len : Maximum size of buffer
75 * @dev : EEPROM device to read
77 * Note: this routine does not validate the EEPROM data.
81 int read_tlv_eeprom(void *eeprom, int offset, int len, int dev);
84 * write_tlv_eeprom - Write the entire EEPROM binary data to the hardware
85 * @eeprom: Pointer to buffer to hold the binary data
86 * @len : Maximum size of buffer
88 * Note: this routine does not validate the EEPROM data.
91 int write_tlv_eeprom(void *eeprom, int len);
94 * read_tlvinfo_tlv_eeprom - Read the TLV from EEPROM, and validate
95 * @eeprom: Pointer to buffer to hold the binary data. Must point to a buffer
96 * of size at least TLV_INFO_MAX_LEN.
97 * @hdr : Points to pointer to TLV header (output)
98 * @first_entry : Points to pointer to first TLV entry (output)
99 * @dev : EEPROM device to read
101 * Store the raw EEPROM data from EEPROM @dev in the @eeprom buffer. If TLV is
102 * valid set *@hdr and *@first_entry.
104 * Returns 0 when read from EEPROM is successful, and the data is valid.
105 * Returns <0 error value when EEPROM read fails. Return -EINVAL when TLV is
110 int read_tlvinfo_tlv_eeprom(void *eeprom, struct tlvinfo_header **hdr,
111 struct tlvinfo_tlv **first_entry, int dev);
113 #else /* !CONFIG_IS_ENABLED(CMD_TLV_EEPROM) */
115 static inline int read_tlv_eeprom(void *eeprom, int offset, int len, int dev)
120 static inline int write_tlv_eeprom(void *eeprom, int len)
126 read_tlvinfo_tlv_eeprom(void *eeprom, struct tlvinfo_header **hdr,
127 struct tlvinfo_tlv **first_entry, int dev)
132 #endif /* CONFIG_IS_ENABLED(CMD_TLV_EEPROM) */
135 * is_valid_tlvinfo_header
137 * Perform sanity checks on the first 11 bytes of the TlvInfo EEPROM
138 * data pointed to by the parameter:
139 * 1. First 8 bytes contain null-terminated ASCII string "TlvInfo"
140 * 2. Version byte is 1
141 * 3. Total length bytes contain value which is less than or equal
142 * to the allowed maximum (2048-11)
145 static inline bool is_valid_tlvinfo_header(struct tlvinfo_header *hdr)
147 return ((strcmp(hdr->signature, TLV_INFO_ID_STRING) == 0) &&
148 (hdr->version == TLV_INFO_VERSION) &&
149 (be16_to_cpu(hdr->totallen) <= TLV_TOTAL_LEN_MAX));
152 #endif /* __TLV_EEPROM_H_ */