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

TOMOYO Linux Cross Reference
Linux/arch/mips/bcm63xx/nvram.c

Version: ~ [ linux-5.11-rc3 ] ~ [ linux-5.10.7 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.89 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.167 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.215 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.251 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.251 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ 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.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * This file is subject to the terms and conditions of the GNU General Public
  3  * License.  See the file "COPYING" in the main directory of this archive
  4  * for more details.
  5  *
  6  * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
  7  * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
  8  * Copyright (C) 2012 Jonas Gorski <jonas.gorski@gmail.com>
  9  */
 10 
 11 #define pr_fmt(fmt) "bcm63xx_nvram: " fmt
 12 
 13 #include <linux/init.h>
 14 #include <linux/crc32.h>
 15 #include <linux/export.h>
 16 #include <linux/kernel.h>
 17 #include <linux/if_ether.h>
 18 
 19 #include <bcm63xx_nvram.h>
 20 
 21 /*
 22  * nvram structure
 23  */
 24 struct bcm963xx_nvram {
 25         u32     version;
 26         u8      reserved1[256];
 27         u8      name[16];
 28         u32     main_tp_number;
 29         u32     psi_size;
 30         u32     mac_addr_count;
 31         u8      mac_addr_base[ETH_ALEN];
 32         u8      reserved2[2];
 33         u32     checksum_old;
 34         u8      reserved3[720];
 35         u32     checksum_high;
 36 };
 37 
 38 #define BCM63XX_DEFAULT_PSI_SIZE        64
 39 
 40 static struct bcm963xx_nvram nvram;
 41 static int mac_addr_used;
 42 
 43 void __init bcm63xx_nvram_init(void *addr)
 44 {
 45         unsigned int check_len;
 46         u32 crc, expected_crc;
 47         u8 hcs_mac_addr[ETH_ALEN] = { 0x00, 0x10, 0x18, 0xff, 0xff, 0xff };
 48 
 49         /* extract nvram data */
 50         memcpy(&nvram, addr, sizeof(nvram));
 51 
 52         /* check checksum before using data */
 53         if (nvram.version <= 4) {
 54                 check_len = offsetof(struct bcm963xx_nvram, reserved3);
 55                 expected_crc = nvram.checksum_old;
 56                 nvram.checksum_old = 0;
 57         } else {
 58                 check_len = sizeof(nvram);
 59                 expected_crc = nvram.checksum_high;
 60                 nvram.checksum_high = 0;
 61         }
 62 
 63         crc = crc32_le(~0, (u8 *)&nvram, check_len);
 64 
 65         if (crc != expected_crc)
 66                 pr_warn("nvram checksum failed, contents may be invalid (expected %08x, got %08x)\n",
 67                         expected_crc, crc);
 68 
 69         /* Cable modems have a different NVRAM which is embedded in the eCos
 70          * firmware and not easily extractible, give at least a MAC address
 71          * pool.
 72          */
 73         if (BCMCPU_IS_3368()) {
 74                 memcpy(nvram.mac_addr_base, hcs_mac_addr, ETH_ALEN);
 75                 nvram.mac_addr_count = 2;
 76         }
 77 }
 78 
 79 u8 *bcm63xx_nvram_get_name(void)
 80 {
 81         return nvram.name;
 82 }
 83 EXPORT_SYMBOL(bcm63xx_nvram_get_name);
 84 
 85 int bcm63xx_nvram_get_mac_address(u8 *mac)
 86 {
 87         u8 *oui;
 88         int count;
 89 
 90         if (mac_addr_used >= nvram.mac_addr_count) {
 91                 pr_err("not enough mac addresses\n");
 92                 return -ENODEV;
 93         }
 94 
 95         memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
 96         oui = mac + ETH_ALEN/2 - 1;
 97         count = mac_addr_used;
 98 
 99         while (count--) {
100                 u8 *p = mac + ETH_ALEN - 1;
101 
102                 do {
103                         (*p)++;
104                         if (*p != 0)
105                                 break;
106                         p--;
107                 } while (p != oui);
108 
109                 if (p == oui) {
110                         pr_err("unable to fetch mac address\n");
111                         return -ENODEV;
112                 }
113         }
114 
115         mac_addr_used++;
116         return 0;
117 }
118 EXPORT_SYMBOL(bcm63xx_nvram_get_mac_address);
119 
120 int bcm63xx_nvram_get_psi_size(void)
121 {
122         if (nvram.psi_size > 0)
123                 return nvram.psi_size;
124 
125         return BCM63XX_DEFAULT_PSI_SIZE;
126 }
127 EXPORT_SYMBOL(bcm63xx_nvram_get_psi_size);
128 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp