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

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

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ 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 /*
  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/bcm963xx_nvram.h>
 14 #include <linux/init.h>
 15 #include <linux/crc32.h>
 16 #include <linux/export.h>
 17 #include <linux/kernel.h>
 18 #include <linux/if_ether.h>
 19 
 20 #include <bcm63xx_nvram.h>
 21 
 22 #define BCM63XX_DEFAULT_PSI_SIZE        64
 23 
 24 static struct bcm963xx_nvram nvram;
 25 static int mac_addr_used;
 26 
 27 void __init bcm63xx_nvram_init(void *addr)
 28 {
 29         u32 crc, expected_crc;
 30         u8 hcs_mac_addr[ETH_ALEN] = { 0x00, 0x10, 0x18, 0xff, 0xff, 0xff };
 31 
 32         /* extract nvram data */
 33         memcpy(&nvram, addr, BCM963XX_NVRAM_V5_SIZE);
 34 
 35         /* check checksum before using data */
 36         if (bcm963xx_nvram_checksum(&nvram, &expected_crc, &crc))
 37                 pr_warn("nvram checksum failed, contents may be invalid (expected %08x, got %08x)\n",
 38                         expected_crc, crc);
 39 
 40         /* Cable modems have a different NVRAM which is embedded in the eCos
 41          * firmware and not easily extractible, give at least a MAC address
 42          * pool.
 43          */
 44         if (BCMCPU_IS_3368()) {
 45                 memcpy(nvram.mac_addr_base, hcs_mac_addr, ETH_ALEN);
 46                 nvram.mac_addr_count = 2;
 47         }
 48 }
 49 
 50 u8 *bcm63xx_nvram_get_name(void)
 51 {
 52         return nvram.name;
 53 }
 54 EXPORT_SYMBOL(bcm63xx_nvram_get_name);
 55 
 56 int bcm63xx_nvram_get_mac_address(u8 *mac)
 57 {
 58         u8 *oui;
 59         int count;
 60 
 61         if (mac_addr_used >= nvram.mac_addr_count) {
 62                 pr_err("not enough mac addresses\n");
 63                 return -ENODEV;
 64         }
 65 
 66         memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
 67         oui = mac + ETH_ALEN/2 - 1;
 68         count = mac_addr_used;
 69 
 70         while (count--) {
 71                 u8 *p = mac + ETH_ALEN - 1;
 72 
 73                 do {
 74                         (*p)++;
 75                         if (*p != 0)
 76                                 break;
 77                         p--;
 78                 } while (p != oui);
 79 
 80                 if (p == oui) {
 81                         pr_err("unable to fetch mac address\n");
 82                         return -ENODEV;
 83                 }
 84         }
 85 
 86         mac_addr_used++;
 87         return 0;
 88 }
 89 EXPORT_SYMBOL(bcm63xx_nvram_get_mac_address);
 90 
 91 int bcm63xx_nvram_get_psi_size(void)
 92 {
 93         if (nvram.psi_size > 0)
 94                 return nvram.psi_size;
 95 
 96         return BCM63XX_DEFAULT_PSI_SIZE;
 97 }
 98 EXPORT_SYMBOL(bcm63xx_nvram_get_psi_size);
 99 

~ [ 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