1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_BCM963XX_NVRAM_H__
3 #define __LINUX_BCM963XX_NVRAM_H__
5 #include <linux/crc32.h>
6 #include <linux/if_ether.h>
7 #include <linux/sizes.h>
8 #include <linux/types.h>
11 * Broadcom BCM963xx SoC board nvram data structure.
13 * The nvram structure varies in size depending on the SoC board version. Use
14 * the appropriate minimum BCM963XX_NVRAM_*_SIZE define for the information
15 * you need instead of sizeof(struct bcm963xx_nvram) as this may change.
18 #define BCM963XX_NVRAM_V4_SIZE 300
19 #define BCM963XX_NVRAM_V5_SIZE (1 * SZ_1K)
21 #define BCM963XX_DEFAULT_PSI_SIZE 64
23 enum bcm963xx_nvram_nand_part {
24 BCM963XX_NVRAM_NAND_PART_BOOT = 0,
25 BCM963XX_NVRAM_NAND_PART_ROOTFS_1,
26 BCM963XX_NVRAM_NAND_PART_ROOTFS_2,
27 BCM963XX_NVRAM_NAND_PART_DATA,
28 BCM963XX_NVRAM_NAND_PART_BBT,
30 __BCM963XX_NVRAM_NAND_NR_PARTS
33 struct bcm963xx_nvram {
40 u8 mac_addr_base[ETH_ALEN];
45 u32 nand_part_offset[__BCM963XX_NVRAM_NAND_NR_PARTS];
46 u32 nand_part_size[__BCM963XX_NVRAM_NAND_NR_PARTS];
51 #define BCM963XX_NVRAM_NAND_PART_OFFSET(nvram, part) \
52 bcm963xx_nvram_nand_part_offset(nvram, BCM963XX_NVRAM_NAND_PART_ ##part)
54 static inline u64 __pure bcm963xx_nvram_nand_part_offset(
55 const struct bcm963xx_nvram *nvram,
56 enum bcm963xx_nvram_nand_part part)
58 return nvram->nand_part_offset[part] * SZ_1K;
61 #define BCM963XX_NVRAM_NAND_PART_SIZE(nvram, part) \
62 bcm963xx_nvram_nand_part_size(nvram, BCM963XX_NVRAM_NAND_PART_ ##part)
64 static inline u64 __pure bcm963xx_nvram_nand_part_size(
65 const struct bcm963xx_nvram *nvram,
66 enum bcm963xx_nvram_nand_part part)
68 return nvram->nand_part_size[part] * SZ_1K;
72 * bcm963xx_nvram_checksum - Verify nvram checksum
74 * @nvram: pointer to full size nvram data structure
75 * @expected_out: optional pointer to store expected checksum value
76 * @actual_out: optional pointer to store actual checksum value
78 * Return: 0 if the checksum is valid, otherwise -EINVAL
80 static int __maybe_unused bcm963xx_nvram_checksum(
81 const struct bcm963xx_nvram *nvram,
82 u32 *expected_out, u32 *actual_out)
87 if (nvram->version <= 4) {
88 expected = nvram->checksum_v4;
89 len = BCM963XX_NVRAM_V4_SIZE - sizeof(u32);
91 expected = nvram->checksum_v5;
92 len = BCM963XX_NVRAM_V5_SIZE - sizeof(u32);
96 * Calculate the CRC32 value for the nvram with a checksum value
97 * of 0 without modifying or copying the nvram by combining:
98 * - The CRC32 of the nvram without the checksum value
99 * - The CRC32 of a zero checksum value (which is also 0)
101 actual = crc32_le_combine(
102 crc32_le(~0, (u8 *)nvram, len), 0, sizeof(u32));
105 *expected_out = expected;
108 *actual_out = actual;
110 return expected == actual ? 0 : -EINVAL;
113 #endif /* __LINUX_BCM963XX_NVRAM_H__ */