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_
10 #include <linux/errno.h>
13 * The Definition of the TlvInfo EEPROM format can be found at onie.org or
18 * TlvInfo header: Layout of the header for the TlvInfo format
20 * See the end of this file for details of this eeprom format
22 struct __attribute__ ((__packed__
)) tlvinfo_header
{
23 char signature
[8]; /* 0x00 - 0x07 EEPROM Tag "TlvInfo" */
24 u8 version
; /* 0x08 Structure version */
25 u16 totallen
; /* 0x09 - 0x0A Length of all data which follows */
28 // Header Field Constants
29 #define TLV_INFO_ID_STRING "TlvInfo"
30 #define TLV_INFO_VERSION 0x01
31 #define TLV_INFO_MAX_LEN 2048
32 #define TLV_TOTAL_LEN_MAX (TLV_INFO_MAX_LEN - \
33 sizeof(struct tlvinfo_header))
36 * TlvInfo TLV: Layout of a TLV field
38 struct __attribute__ ((__packed__
)) tlvinfo_tlv
{
44 /* Maximum length of a TLV value in bytes */
45 #define TLV_VALUE_MAX_LEN 255
50 * Keep these in sync with tlv_code_list in cmd/tlv_eeprom.c
52 #define TLV_CODE_PRODUCT_NAME 0x21
53 #define TLV_CODE_PART_NUMBER 0x22
54 #define TLV_CODE_SERIAL_NUMBER 0x23
55 #define TLV_CODE_MAC_BASE 0x24
56 #define TLV_CODE_MANUF_DATE 0x25
57 #define TLV_CODE_DEVICE_VERSION 0x26
58 #define TLV_CODE_LABEL_REVISION 0x27
59 #define TLV_CODE_PLATFORM_NAME 0x28
60 #define TLV_CODE_ONIE_VERSION 0x29
61 #define TLV_CODE_MAC_SIZE 0x2A
62 #define TLV_CODE_MANUF_NAME 0x2B
63 #define TLV_CODE_MANUF_COUNTRY 0x2C
64 #define TLV_CODE_VENDOR_NAME 0x2D
65 #define TLV_CODE_DIAG_VERSION 0x2E
66 #define TLV_CODE_SERVICE_TAG 0x2F
67 #define TLV_CODE_VENDOR_EXT 0xFD
68 #define TLV_CODE_CRC_32 0xFE
70 #if CONFIG_IS_ENABLED(CMD_TLV_EEPROM)
73 * read_tlv_eeprom - Read the EEPROM binary data from the hardware
74 * @eeprom: Pointer to buffer to hold the binary data
75 * @offset: Offset within EEPROM block to read data from
76 * @len : Maximum size of buffer
77 * @dev : EEPROM device to read
79 * Note: this routine does not validate the EEPROM data.
83 int read_tlv_eeprom(void *eeprom
, int offset
, int len
, int dev
);
86 * write_tlv_eeprom - Write the entire EEPROM binary data to the hardware
87 * @eeprom: Pointer to buffer to hold the binary data
88 * @len : Maximum size of buffer
89 * @dev : EEPROM device to write
91 * Note: this routine does not validate the EEPROM data.
94 int write_tlv_eeprom(void *eeprom
, int len
, int dev
);
97 * read_tlvinfo_tlv_eeprom - Read the TLV from EEPROM, and validate
98 * @eeprom: Pointer to buffer to hold the binary data. Must point to a buffer
99 * of size at least TLV_INFO_MAX_LEN.
100 * @hdr : Points to pointer to TLV header (output)
101 * @first_entry : Points to pointer to first TLV entry (output)
102 * @dev : EEPROM device to read
104 * Store the raw EEPROM data from EEPROM @dev in the @eeprom buffer. If TLV is
105 * valid set *@hdr and *@first_entry.
107 * Returns 0 when read from EEPROM is successful, and the data is valid.
108 * Returns <0 error value when EEPROM read fails. Return -EINVAL when TLV is
113 int read_tlvinfo_tlv_eeprom(void *eeprom
, struct tlvinfo_header
**hdr
,
114 struct tlvinfo_tlv
**first_entry
, int dev
);
116 #else /* !CONFIG_IS_ENABLED(CMD_TLV_EEPROM) */
118 static inline int read_tlv_eeprom(void *eeprom
, int offset
, int len
, int dev
)
123 static inline int write_tlv_eeprom(void *eeprom
, int len
)
129 read_tlvinfo_tlv_eeprom(void *eeprom
, struct tlvinfo_header
**hdr
,
130 struct tlvinfo_tlv
**first_entry
, int dev
)
135 #endif /* CONFIG_IS_ENABLED(CMD_TLV_EEPROM) */
138 * is_valid_tlvinfo_header
140 * Perform sanity checks on the first 11 bytes of the TlvInfo EEPROM
141 * data pointed to by the parameter:
142 * 1. First 8 bytes contain null-terminated ASCII string "TlvInfo"
143 * 2. Version byte is 1
144 * 3. Total length bytes contain value which is less than or equal
145 * to the allowed maximum (2048-11)
148 static inline bool is_valid_tlvinfo_header(struct tlvinfo_header
*hdr
)
150 return ((strcmp(hdr
->signature
, TLV_INFO_ID_STRING
) == 0) &&
151 (hdr
->version
== TLV_INFO_VERSION
) &&
152 (be16_to_cpu(hdr
->totallen
) <= TLV_TOTAL_LEN_MAX
));
155 #endif /* __TLV_EEPROM_H_ */