1#ifndef __LINUX_BCM963XX_NVRAM_H__
2#define __LINUX_BCM963XX_NVRAM_H__
3
4#include <linux/crc32.h>
5#include <linux/if_ether.h>
6#include <linux/sizes.h>
7#include <linux/types.h>
8
9
10
11
12
13
14
15
16
17#define BCM963XX_NVRAM_V4_SIZE 300
18#define BCM963XX_NVRAM_V5_SIZE (1 * SZ_1K)
19
20#define BCM963XX_DEFAULT_PSI_SIZE 64
21
22enum 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,
28
29 __BCM963XX_NVRAM_NAND_NR_PARTS
30};
31
32struct bcm963xx_nvram {
33 u32 version;
34 char bootline[256];
35 char name[16];
36 u32 main_tp_number;
37 u32 psi_size;
38 u32 mac_addr_count;
39 u8 mac_addr_base[ETH_ALEN];
40 u8 __reserved1[2];
41 u32 checksum_v4;
42
43 u8 __reserved2[292];
44 u32 nand_part_offset[__BCM963XX_NVRAM_NAND_NR_PARTS];
45 u32 nand_part_size[__BCM963XX_NVRAM_NAND_NR_PARTS];
46 u8 __reserved3[388];
47 u32 checksum_v5;
48};
49
50#define BCM963XX_NVRAM_NAND_PART_OFFSET(nvram, part) \
51 bcm963xx_nvram_nand_part_offset(nvram, BCM963XX_NVRAM_NAND_PART_ ##part)
52
53static inline u64 __pure bcm963xx_nvram_nand_part_offset(
54 const struct bcm963xx_nvram *nvram,
55 enum bcm963xx_nvram_nand_part part)
56{
57 return nvram->nand_part_offset[part] * SZ_1K;
58}
59
60#define BCM963XX_NVRAM_NAND_PART_SIZE(nvram, part) \
61 bcm963xx_nvram_nand_part_size(nvram, BCM963XX_NVRAM_NAND_PART_ ##part)
62
63static inline u64 __pure bcm963xx_nvram_nand_part_size(
64 const struct bcm963xx_nvram *nvram,
65 enum bcm963xx_nvram_nand_part part)
66{
67 return nvram->nand_part_size[part] * SZ_1K;
68}
69
70
71
72
73
74
75
76
77
78
79static int __maybe_unused bcm963xx_nvram_checksum(
80 const struct bcm963xx_nvram *nvram,
81 u32 *expected_out, u32 *actual_out)
82{
83 u32 expected, actual;
84 size_t len;
85
86 if (nvram->version <= 4) {
87 expected = nvram->checksum_v4;
88 len = BCM963XX_NVRAM_V4_SIZE - sizeof(u32);
89 } else {
90 expected = nvram->checksum_v5;
91 len = BCM963XX_NVRAM_V5_SIZE - sizeof(u32);
92 }
93
94
95
96
97
98
99
100 actual = crc32_le_combine(
101 crc32_le(~0, (u8 *)nvram, len), 0, sizeof(u32));
102
103 if (expected_out)
104 *expected_out = expected;
105
106 if (actual_out)
107 *actual_out = actual;
108
109 return expected == actual ? 0 : -EINVAL;
110};
111
112#endif
113