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
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>
11 #define pr_fmt(fmt) "bcm63xx_nvram: " fmt
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>
20 #include <bcm63xx_nvram.h>
22 static struct bcm963xx_nvram nvram
;
23 static int mac_addr_used
;
25 void __init
bcm63xx_nvram_init(void *addr
)
27 u32 crc
, expected_crc
;
28 u8 hcs_mac_addr
[ETH_ALEN
] = { 0x00, 0x10, 0x18, 0xff, 0xff, 0xff };
30 /* extract nvram data */
31 memcpy(&nvram
, addr
, BCM963XX_NVRAM_V5_SIZE
);
33 /* check checksum before using data */
34 if (bcm963xx_nvram_checksum(&nvram
, &expected_crc
, &crc
))
35 pr_warn("nvram checksum failed, contents may be invalid (expected %08x, got %08x)\n",
38 /* Cable modems have a different NVRAM which is embedded in the eCos
39 * firmware and not easily extractible, give at least a MAC address
42 if (BCMCPU_IS_3368()) {
43 memcpy(nvram
.mac_addr_base
, hcs_mac_addr
, ETH_ALEN
);
44 nvram
.mac_addr_count
= 2;
48 u8
*bcm63xx_nvram_get_name(void)
52 EXPORT_SYMBOL(bcm63xx_nvram_get_name
);
54 int bcm63xx_nvram_get_mac_address(u8
*mac
)
59 if (mac_addr_used
>= nvram
.mac_addr_count
) {
60 pr_err("not enough mac addresses\n");
64 memcpy(mac
, nvram
.mac_addr_base
, ETH_ALEN
);
65 oui
= mac
+ ETH_ALEN
/2 - 1;
66 count
= mac_addr_used
;
69 u8
*p
= mac
+ ETH_ALEN
- 1;
79 pr_err("unable to fetch mac address\n");
87 EXPORT_SYMBOL(bcm63xx_nvram_get_mac_address
);