~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/bcm963xx_nvram.h

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php