0001
0002 #ifndef __LINUX_BCM963XX_NVRAM_H__
0003 #define __LINUX_BCM963XX_NVRAM_H__
0004
0005 #include <linux/crc32.h>
0006 #include <linux/if_ether.h>
0007 #include <linux/sizes.h>
0008 #include <linux/types.h>
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #define BCM963XX_NVRAM_V4_SIZE 300
0019 #define BCM963XX_NVRAM_V5_SIZE (1 * SZ_1K)
0020
0021 #define BCM963XX_DEFAULT_PSI_SIZE 64
0022
0023 enum bcm963xx_nvram_nand_part {
0024 BCM963XX_NVRAM_NAND_PART_BOOT = 0,
0025 BCM963XX_NVRAM_NAND_PART_ROOTFS_1,
0026 BCM963XX_NVRAM_NAND_PART_ROOTFS_2,
0027 BCM963XX_NVRAM_NAND_PART_DATA,
0028 BCM963XX_NVRAM_NAND_PART_BBT,
0029
0030 __BCM963XX_NVRAM_NAND_NR_PARTS
0031 };
0032
0033 struct bcm963xx_nvram {
0034 u32 version;
0035 char bootline[256];
0036 char name[16];
0037 u32 main_tp_number;
0038 u32 psi_size;
0039 u32 mac_addr_count;
0040 u8 mac_addr_base[ETH_ALEN];
0041 u8 __reserved1[2];
0042 u32 checksum_v4;
0043
0044 u8 __reserved2[292];
0045 u32 nand_part_offset[__BCM963XX_NVRAM_NAND_NR_PARTS];
0046 u32 nand_part_size[__BCM963XX_NVRAM_NAND_NR_PARTS];
0047 u8 __reserved3[388];
0048 u32 checksum_v5;
0049 };
0050
0051 #define BCM963XX_NVRAM_NAND_PART_OFFSET(nvram, part) \
0052 bcm963xx_nvram_nand_part_offset(nvram, BCM963XX_NVRAM_NAND_PART_ ##part)
0053
0054 static inline u64 __pure bcm963xx_nvram_nand_part_offset(
0055 const struct bcm963xx_nvram *nvram,
0056 enum bcm963xx_nvram_nand_part part)
0057 {
0058 return nvram->nand_part_offset[part] * SZ_1K;
0059 }
0060
0061 #define BCM963XX_NVRAM_NAND_PART_SIZE(nvram, part) \
0062 bcm963xx_nvram_nand_part_size(nvram, BCM963XX_NVRAM_NAND_PART_ ##part)
0063
0064 static inline u64 __pure bcm963xx_nvram_nand_part_size(
0065 const struct bcm963xx_nvram *nvram,
0066 enum bcm963xx_nvram_nand_part part)
0067 {
0068 return nvram->nand_part_size[part] * SZ_1K;
0069 }
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 static int __maybe_unused bcm963xx_nvram_checksum(
0081 const struct bcm963xx_nvram *nvram,
0082 u32 *expected_out, u32 *actual_out)
0083 {
0084 u32 expected, actual;
0085 size_t len;
0086
0087 if (nvram->version <= 4) {
0088 expected = nvram->checksum_v4;
0089 len = BCM963XX_NVRAM_V4_SIZE - sizeof(u32);
0090 } else {
0091 expected = nvram->checksum_v5;
0092 len = BCM963XX_NVRAM_V5_SIZE - sizeof(u32);
0093 }
0094
0095
0096
0097
0098
0099
0100
0101 actual = crc32_le_combine(
0102 crc32_le(~0, (u8 *)nvram, len), 0, sizeof(u32));
0103
0104 if (expected_out)
0105 *expected_out = expected;
0106
0107 if (actual_out)
0108 *actual_out = actual;
0109
0110 return expected == actual ? 0 : -EINVAL;
0111 };
0112
0113 #endif