chimp_nv_defs.h 15 KB

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