blob: 9be361f6ee77af7e52fd4359366f2478ca66aa01 [file] [log] [blame]
Sheetal Tigadoli58a9eca2019-12-18 20:05:09 +05301/*
2 * Copyright (c) 2016 - 2020, Broadcom
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef BNXNVM_DEFS_H
8#define BNXNVM_DEFS_H
9
10#if defined(__GNUC__)
11 #define PACKED_STRUCT __packed
12#else /* non-GCC compiler */
13
14#ifndef DOS_DRIVERS
15 #pragma pack(push)
16 #pragma pack(1)
17#endif
18 #define PACKED_STRUCT
19#endif
20
21typedef uint32_t u32_t;
22typedef uint8_t u8_t;
23typedef uint16_t u16_t;
24
25#define BNXNVM_DEFAULT_BLOCK_SIZE 4096
26#define BNXNVM_UNUSED_BYTE_VALUE 0xff
27
28#define NV_MAX_BLOCK_SIZE 16384
29
30#define BITS_PER_BYTE (8)
31#define SIZEOF_IN_BITS(x) (sizeof(x)*BITS_PER_BYTE)
32
33/************************/
34/* byte-swapping macros */
35/************************/
36#define BYTE_SWAP_16(x) \
37 ((((u16_t)(x) & 0xff00) >> 8) | \
38 (((u16_t)(x) & 0x00ff) << 8))
39#define BYTE_SWAP_32(x) \
40 ((((u32_t)(x) & 0xff000000) >> 24) | \
41 (((u32_t)(x) & 0x00ff0000) >> 8) | \
42 (((u32_t)(x) & 0x0000ff00) << 8) | \
43 (((u32_t)(x) & 0x000000ff) << 24))
44
45/* auto-detect integer size */
46#define BYTE_SWAP_INT(x) \
47 (SIZEOF_IN_BITS(x) == 16 ? BYTE_SWAP_16(x) : \
48 SIZEOF_IN_BITS(x) == 32 ? BYTE_SWAP_32(x) : (x))
49
50/********************************/
51/* Architecture-specific macros */
52/********************************/
53#ifdef __BIG_ENDIAN__ /* e.g. Motorola */
54
55 #define BE_INT16(x) (x)
56 #define BE_INT32(x) (x)
57 #define BE_INT(x) (x)
58 #define LE_INT16(x) BYTE_SWAP_16(x)
59 #define LE_INT32(x) BYTE_SWAP_32(x)
60 #define LE_INT(x) BYTE_SWAP_INT(x)
61
62#else /* Little Endian (e.g. Intel) */
63
64 #define LE_INT16(x) (x)
65 #define LE_INT32(x) (x)
66 #define LE_INT(x) (x)
67 #define BE_INT16(x) BYTE_SWAP_16(x)
68 #define BE_INT32(x) BYTE_SWAP_32(x)
69 #define BE_INT(x) BYTE_SWAP_INT(x)
70
71#endif
72
73
74enum {
75 NV_OK = 0,
76 NV_NOT_NVRAM,
77 NV_BAD_MB,
78 NV_BAD_DIR_HEADER,
79 NV_BAD_DIR_ENTRY,
80 NV_FW_NOT_FOUND,
81};
82
83typedef struct {
84#define BNXNVM_MASTER_BLOCK_SIG BE_INT32(0x424E5834) /*"BNX4"*/
85 /* Signature*/
86 u32_t sig;
87 /* Length of Master Block Header, in bytes [32] */
88 u32_t length;
89 /* Block size, in bytes [4096] */
90 u32_t block_size;
91 /* Byte-offset to Directory Block (translated) */
92 u32_t directory_offset;
93 /* Byte-offset to Block Redirection Table (non-translated) */
94 u32_t redirect_offset;
95 /* Size, in bytes of Reserved Blocks region (at end of NVRAM) */
96 u32_t reserved_size;
97 /*
98 * Size of NVRAM (in bytes) - may be used to
99 * override auto-detected size
100 */
101 u32_t nvram_size;
102 /* CRC-32 (IEEE 802.3 compatible) of the above */
103 u32_t chksum;
104} PACKED_STRUCT bnxnvm_master_block_header_t;
105
106typedef struct {
107#define BNXNVM_DIRECTORY_BLOCK_SIG BE_INT32(0x44697230) /* "Dir0" */
108 /* Signature */
109 u32_t sig;
110 /* Length of Directory Header, in bytes [16] */
111 u32_t length;
112 /* Number of Directory Entries */
113 u32_t entries;
114 /* Length of each Directory Entry, in bytes [24] */
115 u32_t entry_length;
116} PACKED_STRUCT bnxnvm_directory_block_header_t;
117
118typedef struct {
119 /* Directory Entry Type (see enum bnxnvm_directory_type) */
120 u16_t type;
121 /* Instance of this Directory Entry type (0-based) */
122 u16_t ordinal;
123 /*
124 * Directory Entry Extension flags used to identify
125 * secondary instances of a type:ordinal combinations
126 */
127 u16_t ext;
128 /* Directory Entry Attribute flags used to describe the item contents */
129 u16_t attr;
130 /* Item location in NVRAM specified as offset (in bytes) */
131 u32_t item_location;
132 /*
133 * Length of NVRAM item in bytes
134 * (including padding - multiple of block size)
135 */
136 u32_t item_length;
137 /* Length of item data in bytes (excluding padding) */
138 u32_t data_length;
139 /*
140 * CRC-32 (IEEE 802.3 compatible) of item data
141 * (excluding padding) (optional)
142 */
143 u32_t data_chksum;
144} PACKED_STRUCT bnxnvm_directory_entry_t;
145
146enum bnxnvm_version_format {
147 /* US-ASCII string (not necessarily null-terminated) */
148 BNX_VERSION_FMT_ASCII = 0,
149 /* Each field 16-bits, displayed as unpadded decimal (e.g. "1.2.3.4") */
150 BNX_VERSION_FMT_DEC = 1,
151 /* A single hexadecimal value, up to 64-bits (no dots) */
152 BNX_VERSION_FMT_HEX = 2,
153 /* Multiple version values (three 8-bit version fields) */
154 BNX_VERSION_FMT_MULTI = 3
155};
156
157/* This structure definition must not change: */
158typedef struct {
159 u16_t flags; /* bit-flags (defaults to 0x0000) */
160 u8_t version_format; /* enum bnxnvm_version_format */
161 u8_t version_length; /* in bytes */
162 u8_t version[16]; /* version value */
163 u16_t dir_type; /* enum bnxnvm_directory_type */
164 /* size of the entire trailer (to locate end of component data) */
165 u16_t trailer_length;
166#define BNXNVM_COMPONENT_TRAILER_SIG BE_INT32(0x54726c72) /* "Trlr" */
167 u32_t sig;
168 u32_t chksum; /* CRC-32 of all bytes to this point */
169} PACKED_STRUCT bnxnvm_component_trailer_base_t;
170
171typedef struct {
172 /*
173 * new trailer members (e.g. digital signature)
174 * go here (insert at top):
175 */
176 u8_t rsa_sig[256]; /* 2048-bit RSA-encrypted SHA-256 hash */
177 bnxnvm_component_trailer_base_t base;
178} PACKED_STRUCT bnxnvm_component_trailer_t;
179
180#define BNX_MAX_LEN_DIR_NAME 12
181#define BNX_MAX_LEN_DIR_DESC 50
182/*********************************************************
183 * NVRAM Directory Entry/Item Types, Names, and Descriptions
184 *
185 * If you see a name or description that needs improvement,
186 * please correct it or raise for discussion.
187 * When adding a new directory type, it would be appreciated
188 * if you also updated ../../libs/nvm/bnxt_nvm_str.c.
189 * DIR_NAME macros may contain up to 12 alpha-numeric
190 * US-ASCII characters only, camelCase is preferred for clarity.
191 * DIR_DESC macros may contain up to 50 US-ASCII characters
192 * providing a verbose description of the directory type.
193 */
194enum bnxnvm_directory_type {
195 /* 0x00 Unused directory entry, available for use */
196 BNX_DIR_TYPE_UNUSED = 0,
197#define BNX_DIR_NAME_UNUSED "unused"
198#define BNX_DIR_DESC_UNUSED "Deleted directory entry, available for reuse"
199 /* 0x01 Package installation log */
200 BNX_DIR_TYPE_PKG_LOG = 1,
201#define BNX_DIR_NAME_PKG_LOG "pkgLog"
202#define BNX_DIR_DESC_PKG_LOG "Package Installation Log"
203 BNX_DIR_TYPE_CHIMP_PATCH = 3,
204#define BNX_DIR_NAME_CHIMP_PATCH "chimpPatch"
205#define BNX_DIR_DESC_CHIMP_PATCH "ChiMP Patch Firmware"
206 /* 0x04 ChiMP firmware: Boot Code phase 1 */
207 BNX_DIR_TYPE_BOOTCODE = 4,
208#define BNX_DIR_NAME_BOOTCODE "chimpBoot"
209#define BNX_DIR_DESC_BOOTCODE "Chip Management Processor Boot Firmware"
210 /* 0x05 VPD data block */
211 BNX_DIR_TYPE_VPD = 5,
212#define BNX_DIR_NAME_VPD "VPD"
213#define BNX_DIR_DESC_VPD "Vital Product Data"
214 /* 0x06 Exp ROM MBA */
215 BNX_DIR_TYPE_EXP_ROM_MBA = 6,
216#define BNX_DIR_NAME_EXP_ROM_MBA "MBA"
217#define BNX_DIR_DESC_EXP_ROM_MBA "Multiple Boot Agent Expansion ROM"
218 BNX_DIR_TYPE_AVS = 7, /* 0x07 AVS FW */
219#define BNX_DIR_NAME_AVS "AVS"
220#define BNX_DIR_DESC_AVS "Adaptive Voltage Scaling Firmware"
221 BNX_DIR_TYPE_PCIE = 8, /* 0x08 PCIE FW */
222#define BNX_DIR_NAME_PCIE "PCIEucode"
223#define BNX_DIR_DESC_PCIE "PCIe Microcode"
224 BNX_DIR_TYPE_PORT_MACRO = 9, /* 0x09 PORT MACRO FW */
225#define BNX_DIR_NAME_PORT_MACRO "portMacro"
226#define BNX_DIR_DESC_PORT_MACRO "Port Macro Firmware"
227 BNX_DIR_TYPE_APE_FW = 10, /* 0x0A APE Firmware */
228#define BNX_DIR_NAME_APE_FW "apeFW"
229#define BNX_DIR_DESC_APE_FW "Application Processing Engine Firmware"
230 /* 0x0B Patch firmware executed by APE ROM */
231 BNX_DIR_TYPE_APE_PATCH = 11,
232#define BNX_DIR_NAME_APE_PATCH "apePatch"
233#define BNX_DIR_DESC_APE_PATCH "APE Patch Firmware"
234 BNX_DIR_TYPE_KONG_FW = 12, /* 0x0C Kong Firmware */
235#define BNX_DIR_NAME_KONG_FW "kongFW"
236#define BNX_DIR_DESC_KONG_FW "Kong Firmware"
237 /* 0x0D Patch firmware executed by Kong ROM */
238 BNX_DIR_TYPE_KONG_PATCH = 13,
239#define BNX_DIR_NAME_KONG_PATCH "kongPatch"
240#define BNX_DIR_DESC_KONG_PATCH "Kong Patch Firmware"
241 BNX_DIR_TYPE_BONO_FW = 14, /* 0x0E Bono Firmware */
242#define BNX_DIR_NAME_BONO_FW "bonoFW"
243#define BNX_DIR_DESC_BONO_FW "Bono Firmware"
244 /* 0x0F Patch firmware executed by Bono ROM */
245 BNX_DIR_TYPE_BONO_PATCH = 15,
246#define BNX_DIR_NAME_BONO_PATCH "bonoPatch"
247#define BNX_DIR_DESC_BONO_PATCH "Bono Patch Firmware"
248 BNX_DIR_TYPE_TANG_FW = 16, /* 0x10 Tang firmware */
249#define BNX_DIR_NAME_TANG_FW "tangFW"
250#define BNX_DIR_DESC_TANG_FW "Tang Firmware"
251 /* 0x11 Patch firmware executed by Tang ROM */
252 BNX_DIR_TYPE_TANG_PATCH = 17,
253#define BNX_DIR_NAME_TANG_PATCH "tangPatch"
254#define BNX_DIR_DESC_TANG_PATCH "Tang Patch Firmware"
255 /* 0x12 ChiMP firmware: Boot Code phase 2 (loaded by phase 1) */
256 BNX_DIR_TYPE_BOOTCODE_2 = 18,
257#define BNX_DIR_NAME_BOOTCODE_2 "chimpHWRM"
258#define BNX_DIR_DESC_BOOTCODE_2 "ChiMP Hardware Resource Manager Firmware"
259 BNX_DIR_TYPE_CCM = 19, /* 0x13 CCM ROM binary */
260#define BNX_DIR_NAME_CCM "CCM"
261#define BNX_DIR_DESC_CCM "Comprehensive Configuration Management"
262 /* 0x14 PCI-IDs, PCI-related configuration properties */
263 BNX_DIR_TYPE_PCI_CFG = 20,
264#define BNX_DIR_NAME_PCI_CFG "pciCFG"
265#define BNX_DIR_DESC_PCI_CFG "PCIe Configuration Data"
266
267 BNX_DIR_TYPE_TSCF_UCODE = 21, /* 0x15 TSCF micro-code */
268#define BNX_DIR_NAME_TSCF_UCODE "PHYucode"
269#define BNX_DIR_DESC_TSCF_UCODE "Falcon PHY Microcode"
270 BNX_DIR_TYPE_ISCSI_BOOT = 22, /* 0x16 iSCSI Boot */
271#define BNX_DIR_NAME_ISCSI_BOOT "iSCSIboot"
272#define BNX_DIR_DESC_ISCSI_BOOT "iSCSI Boot Software Initiator"
273 /* 0x18 iSCSI Boot IPV6 - ***DEPRECATED*** */
274 BNX_DIR_TYPE_ISCSI_BOOT_IPV6 = 24,
275 /* 0x19 iSCSI Boot IPV4N6 - ***DEPRECATED*** */
276 BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6 = 25,
277 BNX_DIR_TYPE_ISCSI_BOOT_CFG = 26, /* 0x1a iSCSI Boot CFG v6 */
278#define BNX_DIR_NAME_ISCSI_BOOT_CFG "iSCSIcfg"
279#define BNX_DIR_DESC_ISCSI_BOOT_CFG "iSCSI Boot Configuration Data"
280 BNX_DIR_TYPE_EXT_PHY = 27, /* 0x1b External PHY FW */
281#define BNX_DIR_NAME_EXT_PHY "extPHYfw"
282#define BNX_DIR_DESC_EXT_PHY "External PHY Firmware"
283 BNX_DIR_TYPE_MODULES_PN = 28, /* 0x1c Modules PartNum list */
284#define BNX_DIR_NAME_MODULES_PN "modPartNums"
285#define BNX_DIR_DESC_MODULES_PN "Optical Modules Part Number List"
286 BNX_DIR_TYPE_SHARED_CFG = 40, /* 0x28 shared configuration block */
287#define BNX_DIR_NAME_SHARED_CFG "sharedCFG"
288#define BNX_DIR_DESC_SHARED_CFG "Shared Configuration Data"
289 BNX_DIR_TYPE_PORT_CFG = 41, /* 0x29 port configuration block */
290#define BNX_DIR_NAME_PORT_CFG "portCFG"
291#define BNX_DIR_DESC_PORT_CFG "Port Configuration Data"
292 BNX_DIR_TYPE_FUNC_CFG = 42, /* 0x2A func configuration block */
293#define BNX_DIR_NAME_FUNC_CFG "funcCFG"
294#define BNX_DIR_DESC_FUNC_CFG "Function Configuration Data"
295
296 /* Management Firmware (TruManage) related dir entries*/
297 /* 0x30 Management firmware configuration (see BMCFG library)*/
298 BNX_DIR_TYPE_MGMT_CFG = 48,
299#define BNX_DIR_NAME_MGMT_CFG "mgmtCFG"
300#define BNX_DIR_DESC_MGMT_CFG "Out-of-band Management Configuration Data"
301 BNX_DIR_TYPE_MGMT_DATA = 49, /* 0x31 "Opaque Management Data" */
302#define BNX_DIR_NAME_MGMT_DATA "mgmtData"
303#define BNX_DIR_DESC_MGMT_DATA "Out-of-band Management Data"
304 BNX_DIR_TYPE_MGMT_WEB_DATA = 50, /* 0x32 "Web GUI" file data */
305#define BNX_DIR_NAME_MGMT_WEB_DATA "webData"
306#define BNX_DIR_DESC_MGMT_WEB_DATA "Out-of-band Management Web Data"
307 /* 0x33 "Web GUI" file metadata */
308 BNX_DIR_TYPE_MGMT_WEB_META = 51,
309#define BNX_DIR_NAME_MGMT_WEB_META "webMeta"
310#define BNX_DIR_DESC_MGMT_WEB_META "Out-of-band Management Web Metadata"
311 /* 0x34 Management firmware Event Log (a.k.a. "SEL") */
312 BNX_DIR_TYPE_MGMT_EVENT_LOG = 52,
313#define BNX_DIR_NAME_MGMT_EVENT_LOG "eventLog"
314#define BNX_DIR_DESC_MGMT_EVENT_LOG "Out-of-band Management Event Log"
315 /* 0x35 Management firmware Audit Log */
316 BNX_DIR_TYPE_MGMT_AUDIT_LOG = 53
317#define BNX_DIR_NAME_MGMT_AUDIT_LOG "auditLog"
318#define BNX_DIR_DESC_MGMT_AUDIT_LOG "Out-of-band Management Audit Log"
319
320};
321
322/* For backwards compatibility only, may be removed later */
323#define BNX_DIR_TYPE_ISCSI_BOOT_CFG6 BNX_DIR_TYPE_ISCSI_BOOT_CFG
324
325/* Firmware NVM items of "APE BIN" format are identified with
326 * the following macro:
327 */
328#define BNX_DIR_TYPE_IS_APE_BIN_FMT(type)\
329 ((type) == BNX_DIR_TYPE_CHIMP_PATCH \
330 || (type) == BNX_DIR_TYPE_BOOTCODE \
331 || (type) == BNX_DIR_TYPE_BOOTCODE_2 \
332 || (type) == BNX_DIR_TYPE_APE_FW \
333 || (type) == BNX_DIR_TYPE_APE_PATCH \
334 || (type) == BNX_DIR_TYPE_TANG_FW \
335 || (type) == BNX_DIR_TYPE_TANG_PATCH \
336 || (type) == BNX_DIR_TYPE_KONG_FW \
337 || (type) == BNX_DIR_TYPE_KONG_PATCH \
338 || (type) == BNX_DIR_TYPE_BONO_FW \
339 || (type) == BNX_DIR_TYPE_BONO_PATCH \
340 )
341
342/* Other (non APE BIN) executable NVM items are identified with
343 * the following macro:
344 */
345#define BNX_DIR_TYPE_IS_OTHER_EXEC(type)\
346 ((type) == BNX_DIR_TYPE_AVS \
347 || (type) == BNX_DIR_TYPE_EXP_ROM_MBA \
348 || (type) == BNX_DIR_TYPE_PCIE \
349 || (type) == BNX_DIR_TYPE_TSCF_UCODE \
350 || (type) == BNX_DIR_TYPE_EXT_PHY \
351 || (type) == BNX_DIR_TYPE_CCM \
352 || (type) == BNX_DIR_TYPE_ISCSI_BOOT \
353 )
354
355/* Executable NVM items (e.g. microcode, firmware, software) identified
356 * with the following macro
357 */
358#define BNX_DIR_TYPE_IS_EXECUTABLE(type) \
359 (BNX_DIR_TYPE_IS_APE_BIN_FMT(type) \
360 || BNX_DIR_TYPE_IS_OTHER_EXEC(type))
361
362#define BNX_DIR_ORDINAL_FIRST 0 /* Ordinals are 0-based */
363
364/* No extension flags for this directory entry */
365#define BNX_DIR_EXT_NONE 0
366/* Directory entry is inactive (not used, not hidden,
367 * not available for reuse)
368 */
369#define BNX_DIR_EXT_INACTIVE (1 << 0)
370/* Directory content is a temporary staging location for
371 * updating the primary (non-update) directory entry contents
372 * (e.g. performing a secure firmware update)
373 */
374#define BNX_DIR_EXT_UPDATE (1 << 1)
375
376/* No attribute flags set for this directory entry */
377#define BNX_DIR_ATTR_NONE 0
378/* Directory entry checksum of contents is purposely incorrect */
379#define BNX_DIR_ATTR_NO_CHKSUM (1 << 0)
380/* Directory contents are in the form of a property-stream
381 * (e.g. configuration properties)
382 */
383#define BNX_DIR_ATTR_PROP_STREAM (1 << 1)
384/* Directory content (e.g. iSCSI boot) supports IPv4 */
385#define BNX_DIR_ATTR_IPv4 (1 << 2)
386/* Directory content (e.g. iSCSI boot) supports IPv6 */
387#define BNX_DIR_ATTR_IPv6 (1 << 3)
388/* Directory content includes standard NVM component trailer
389 * (bnxnvm_component_trailer_t)
390 */
391#define BNX_DIR_ATTR_TRAILER (1 << 4)
392
393/* Index of tab-delimited fields in each package log
394 * (BNX_DIR_TYPE_PKG_LOG) record (\n-terminated line):
395 */
396enum bnxnvm_pkglog_field_index {
397 /* Package installation date/time in ISO-8601 format */
398 BNX_PKG_LOG_FIELD_IDX_INSTALLED_TIMESTAMP = 0,
399 /* Installed package description (from package header) or "N/A" */
400 BNX_PKG_LOG_FIELD_IDX_PKG_DESCRIPTION = 1,
401 /* Installed package version string (from package header) or "N/A" */
402 BNX_PKG_LOG_FIELD_IDX_PKG_VERSION = 2,
403 /* Installed package creation/modification timestamp (ISO-8601) */
404 BNX_PKG_LOG_FIELD_IDX_PKG_TIMESTAMP = 3,
405 /* Installed package checksum in hexadecimal (CRC-32) or "N/A" */
406 BNX_PKG_LOG_FIELD_IDX_PKG_CHECKSUM = 4,
407 /* Total number of packaged items applied in this installation */
408 BNX_PKG_LOG_FIELD_IDX_INSTALLED_ITEMS = 5,
409 /* Hexadecimal bit-mask identifying which items were installed */
410 BNX_PKG_LOG_FIELD_IDX_INSTALLED_MASK = 6
411};
412
413#if !defined(__GNUC__)
414#ifndef DOS_DRIVERS
415 #pragma pack(pop) /* original packing */
416#endif
417#endif
418
419#endif /* Don't add anything after this line */