1 #ifndef __LINUX_BCM963XX_NVRAM_H__
2 #define __LINUX_BCM963XX_NVRAM_H__
4 #include <linux/crc32.h>
5 #include <linux/if_ether.h>
6 #include <linux/sizes.h>
7 #include <linux/types.h>
10 * Broadcom BCM963xx SoC board nvram data structure.
12 * The nvram structure varies in size depending on the SoC board version. Use
13 * the appropriate minimum BCM963XX_NVRAM_*_SIZE define for the information
14 * you need instead of sizeof(struct bcm963xx_nvram) as this may change.
17 #define BCM963XX_NVRAM_V4_SIZE 300
18 #define BCM963XX_NVRAM_V5_SIZE (1 * SZ_1K)
20 #define BCM963XX_DEFAULT_PSI_SIZE 64
22 enum bcm963xx_nvram_nand_part {
23 BCM963XX_NVRAM_NAND_PART_BOOT = 0,
24 BCM963XX_NVRAM_NAND_PART_ROOTFS_1,
25 BCM963XX_NVRAM_NAND_PART_ROOTFS_2,
26 BCM963XX_NVRAM_NAND_PART_DATA,
27 BCM963XX_NVRAM_NAND_PART_BBT,
29 __BCM963XX_NVRAM_NAND_NR_PARTS
32 struct bcm963xx_nvram {
39 u8 mac_addr_base[ETH_ALEN];
44 u32 nand_part_offset[__BCM963XX_NVRAM_NAND_NR_PARTS];
45 u32 nand_part_size[__BCM963XX_NVRAM_NAND_NR_PARTS];
50 #define BCM963XX_NVRAM_NAND_PART_OFFSET(nvram, part) \
51 bcm963xx_nvram_nand_part_offset(nvram, BCM963XX_NVRAM_NAND_PART_ ##part)
53 static inline u64 __pure bcm963xx_nvram_nand_part_offset(
54 const struct bcm963xx_nvram *nvram,
55 enum bcm963xx_nvram_nand_part part)
57 return nvram->nand_part_offset[part] * SZ_1K;
60 #define BCM963XX_NVRAM_NAND_PART_SIZE(nvram, part) \
61 bcm963xx_nvram_nand_part_size(nvram, BCM963XX_NVRAM_NAND_PART_ ##part)
63 static inline u64 __pure bcm963xx_nvram_nand_part_size(
64 const struct bcm963xx_nvram *nvram,
65 enum bcm963xx_nvram_nand_part part)
67 return nvram->nand_part_size[part] * SZ_1K;
71 * bcm963xx_nvram_checksum - Verify nvram checksum
73 * @nvram: pointer to full size nvram data structure
74 * @expected_out: optional pointer to store expected checksum value
75 * @actual_out: optional pointer to store actual checksum value
77 * Return: 0 if the checksum is valid, otherwise -EINVAL
79 static int __maybe_unused bcm963xx_nvram_checksum(
80 const struct bcm963xx_nvram *nvram,
81 u32 *expected_out, u32 *actual_out)
86 if (nvram->version <= 4) {
87 expected = nvram->checksum_v4;
88 len = BCM963XX_NVRAM_V4_SIZE - sizeof(u32);
90 expected = nvram->checksum_v5;
91 len = BCM963XX_NVRAM_V5_SIZE - sizeof(u32);
95 * Calculate the CRC32 value for the nvram with a checksum value
96 * of 0 without modifying or copying the nvram by combining:
97 * - The CRC32 of the nvram without the checksum value
98 * - The CRC32 of a zero checksum value (which is also 0)
100 actual = crc32_le_combine(
101 crc32_le(~0, (u8 *)nvram, len), 0, sizeof(u32));
104 *expected_out = expected;
107 *actual_out = actual;
109 return expected == actual ? 0 : -EINVAL;
112 #endif /* __LINUX_BCM963XX_NVRAM_H__ */