1
2
3
4
5
6
7#ifndef __TLV_EEPROM_H_
8#define __TLV_EEPROM_H_
9
10
11
12
13
14
15
16
17
18
19
20struct __attribute__ ((__packed__)) tlvinfo_header {
21 char signature[8];
22 u8 version;
23 u16 totallen;
24};
25
26
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))
32
33
34
35
36struct __attribute__ ((__packed__)) tlvinfo_tlv {
37 u8 type;
38 u8 length;
39 u8 value[0];
40};
41
42
43#define TLV_VALUE_MAX_LEN 255
44
45
46
47
48
49
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
67
68#if CONFIG_IS_ENABLED(CMD_TLV_EEPROM)
69
70
71
72
73
74
75
76
77
78
79
80
81int read_tlv_eeprom(void *eeprom, int offset, int len, int dev);
82
83
84
85
86
87
88
89
90
91int write_tlv_eeprom(void *eeprom, int len);
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110int read_tlvinfo_tlv_eeprom(void *eeprom, struct tlvinfo_header **hdr,
111 struct tlvinfo_tlv **first_entry, int dev);
112
113#else
114
115static inline int read_tlv_eeprom(void *eeprom, int offset, int len, int dev)
116{
117 return -ENOSYS;
118}
119
120static inline int write_tlv_eeprom(void *eeprom, int len)
121{
122 return -ENOSYS;
123}
124
125static inline int
126read_tlvinfo_tlv_eeprom(void *eeprom, struct tlvinfo_header **hdr,
127 struct tlvinfo_tlv **first_entry, int dev)
128{
129 return -ENOSYS;
130}
131
132#endif
133
134
135
136
137
138
139
140
141
142
143
144
145static inline bool is_valid_tlvinfo_header(struct tlvinfo_header *hdr)
146{
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));
150}
151
152#endif
153