Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: BCM63XX: move nvram functions into their own file

Refactor nvram related functions into its own unit for easier expansion
and exposure of the values to other drivers.

Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
Patchwork: http://patchwork.linux-mips.org/patch/4516
Signed-off-by: John Crispin <blogic@openwrt.org>

authored by

Jonas Gorski and committed by
John Crispin
e7e333cb ba00e2e5

+154 -80
+4 -3
arch/mips/bcm63xx/Makefile
··· 1 - obj-y += clk.o cpu.o cs.o gpio.o irq.o prom.o reset.o setup.o \ 2 - timer.o dev-dsp.o dev-enet.o dev-flash.o dev-pcmcia.o \ 3 - dev-rng.o dev-spi.o dev-uart.o dev-wdt.o dev-usb-usbd.o 1 + obj-y += clk.o cpu.o cs.o gpio.o irq.o nvram.o prom.o reset.o \ 2 + setup.o timer.o dev-dsp.o dev-enet.o dev-flash.o \ 3 + dev-pcmcia.o dev-rng.o dev-spi.o dev-uart.o dev-wdt.o \ 4 + dev-usb-usbd.o 4 5 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o 5 6 6 7 obj-y += boards/
+11 -60
arch/mips/bcm63xx/boards/board_bcm963xx.c
··· 18 18 #include <bcm63xx_dev_uart.h> 19 19 #include <bcm63xx_regs.h> 20 20 #include <bcm63xx_io.h> 21 + #include <bcm63xx_nvram.h> 21 22 #include <bcm63xx_dev_pci.h> 22 23 #include <bcm63xx_dev_enet.h> 23 24 #include <bcm63xx_dev_dsp.h> ··· 30 29 31 30 #define PFX "board_bcm963xx: " 32 31 33 - static struct bcm963xx_nvram nvram; 34 - static unsigned int mac_addr_used; 35 32 static struct board_info board; 36 33 37 34 /* ··· 715 716 } 716 717 717 718 /* 718 - * register & return a new board mac address 719 - */ 720 - static int board_get_mac_address(u8 *mac) 721 - { 722 - u8 *oui; 723 - int count; 724 - 725 - if (mac_addr_used >= nvram.mac_addr_count) { 726 - printk(KERN_ERR PFX "not enough mac address\n"); 727 - return -ENODEV; 728 - } 729 - 730 - memcpy(mac, nvram.mac_addr_base, ETH_ALEN); 731 - oui = mac + ETH_ALEN/2 - 1; 732 - count = mac_addr_used; 733 - 734 - while (count--) { 735 - u8 *p = mac + ETH_ALEN - 1; 736 - 737 - do { 738 - (*p)++; 739 - if (*p != 0) 740 - break; 741 - p--; 742 - } while (p != oui); 743 - 744 - if (p == oui) { 745 - printk(KERN_ERR PFX "unable to fetch mac address\n"); 746 - return -ENODEV; 747 - } 748 - } 749 - 750 - mac_addr_used++; 751 - return 0; 752 - } 753 - 754 - /* 755 719 * early init callback, read nvram data from flash and checksum it 756 720 */ 757 721 void __init board_prom_init(void) 758 722 { 759 - unsigned int check_len, i; 760 - u8 *boot_addr, *cfe, *p; 723 + unsigned int i; 724 + u8 *boot_addr, *cfe; 761 725 char cfe_version[32]; 726 + char *board_name; 762 727 u32 val; 763 728 764 729 /* read base address of boot chip select (0) ··· 745 782 strcpy(cfe_version, "unknown"); 746 783 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version); 747 784 748 - /* extract nvram data */ 749 - memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram)); 750 - 751 - /* check checksum before using data */ 752 - if (nvram.version <= 4) 753 - check_len = offsetof(struct bcm963xx_nvram, checksum_old); 754 - else 755 - check_len = sizeof(nvram); 756 - val = 0; 757 - p = (u8 *)&nvram; 758 - while (check_len--) 759 - val += *p; 760 - if (val) { 785 + if (bcm63xx_nvram_init(boot_addr + BCM963XX_NVRAM_OFFSET)) { 761 786 printk(KERN_ERR PFX "invalid nvram checksum\n"); 762 787 return; 763 788 } 764 789 790 + board_name = bcm63xx_nvram_get_name(); 765 791 /* find board by name */ 766 792 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) { 767 - if (strncmp(nvram.name, bcm963xx_boards[i]->name, 768 - sizeof(nvram.name))) 793 + if (strncmp(board_name, bcm963xx_boards[i]->name, 16)) 769 794 continue; 770 795 /* copy, board desc array is marked initdata */ 771 796 memcpy(&board, bcm963xx_boards[i], sizeof(board)); ··· 763 812 /* bail out if board is not found, will complain later */ 764 813 if (!board.name[0]) { 765 814 char name[17]; 766 - memcpy(name, nvram.name, 16); 815 + memcpy(name, board_name, 16); 767 816 name[16] = 0; 768 817 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n", 769 818 name); ··· 841 890 bcm63xx_pcmcia_register(); 842 891 843 892 if (board.has_enet0 && 844 - !board_get_mac_address(board.enet0.mac_addr)) 893 + !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr)) 845 894 bcm63xx_enet_register(0, &board.enet0); 846 895 847 896 if (board.has_enet1 && 848 - !board_get_mac_address(board.enet1.mac_addr)) 897 + !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr)) 849 898 bcm63xx_enet_register(1, &board.enet1); 850 899 851 900 if (board.has_usbd) ··· 858 907 * do this after registering enet devices 859 908 */ 860 909 #ifdef CONFIG_SSB_PCIHOST 861 - if (!board_get_mac_address(bcm63xx_sprom.il0mac)) { 910 + if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) { 862 911 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN); 863 912 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN); 864 913 if (ssb_arch_register_fallback_sprom(
+104
arch/mips/bcm63xx/nvram.c
··· 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/export.h> 15 + #include <linux/kernel.h> 16 + #include <linux/if_ether.h> 17 + 18 + #include <bcm63xx_nvram.h> 19 + 20 + /* 21 + * nvram structure 22 + */ 23 + struct bcm963xx_nvram { 24 + u32 version; 25 + u8 reserved1[256]; 26 + u8 name[16]; 27 + u32 main_tp_number; 28 + u32 psi_size; 29 + u32 mac_addr_count; 30 + u8 mac_addr_base[ETH_ALEN]; 31 + u8 reserved2[2]; 32 + u32 checksum_old; 33 + u8 reserved3[720]; 34 + u32 checksum_high; 35 + }; 36 + 37 + static struct bcm963xx_nvram nvram; 38 + static int mac_addr_used; 39 + 40 + int __init bcm63xx_nvram_init(void *addr) 41 + { 42 + unsigned int check_len; 43 + u8 *p; 44 + u32 val; 45 + 46 + /* extract nvram data */ 47 + memcpy(&nvram, addr, sizeof(nvram)); 48 + 49 + /* check checksum before using data */ 50 + if (nvram.version <= 4) 51 + check_len = offsetof(struct bcm963xx_nvram, checksum_old); 52 + else 53 + check_len = sizeof(nvram); 54 + val = 0; 55 + p = (u8 *)&nvram; 56 + 57 + while (check_len--) 58 + val += *p; 59 + if (val) 60 + return -EINVAL; 61 + 62 + return 0; 63 + } 64 + 65 + u8 *bcm63xx_nvram_get_name(void) 66 + { 67 + return nvram.name; 68 + } 69 + EXPORT_SYMBOL(bcm63xx_nvram_get_name); 70 + 71 + int bcm63xx_nvram_get_mac_address(u8 *mac) 72 + { 73 + u8 *oui; 74 + int count; 75 + 76 + if (mac_addr_used >= nvram.mac_addr_count) { 77 + pr_err("not enough mac addresses\n"); 78 + return -ENODEV; 79 + } 80 + 81 + memcpy(mac, nvram.mac_addr_base, ETH_ALEN); 82 + oui = mac + ETH_ALEN/2 - 1; 83 + count = mac_addr_used; 84 + 85 + while (count--) { 86 + u8 *p = mac + ETH_ALEN - 1; 87 + 88 + do { 89 + (*p)++; 90 + if (*p != 0) 91 + break; 92 + p--; 93 + } while (p != oui); 94 + 95 + if (p == oui) { 96 + pr_err("unable to fetch mac address\n"); 97 + return -ENODEV; 98 + } 99 + } 100 + 101 + mac_addr_used++; 102 + return 0; 103 + } 104 + EXPORT_SYMBOL(bcm63xx_nvram_get_mac_address);
+35
arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h
··· 1 + #ifndef BCM63XX_NVRAM_H 2 + #define BCM63XX_NVRAM_H 3 + 4 + #include <linux/types.h> 5 + 6 + /** 7 + * bcm63xx_nvram_init() - initializes nvram 8 + * @nvram: address of the nvram data 9 + * 10 + * Initialized the local nvram copy from the target address and checks 11 + * its checksum. 12 + * 13 + * Returns 0 on success. 14 + */ 15 + int __init bcm63xx_nvram_init(void *nvram); 16 + 17 + /** 18 + * bcm63xx_nvram_get_name() - returns the board name according to nvram 19 + * 20 + * Returns the board name field from nvram. Note that it might not be 21 + * null terminated if it is exactly 16 bytes long. 22 + */ 23 + u8 *bcm63xx_nvram_get_name(void); 24 + 25 + /** 26 + * bcm63xx_nvram_get_mac_address() - register & return a new mac address 27 + * @mac: pointer to array for allocated mac 28 + * 29 + * Registers and returns a mac address from the allocated macs from nvram. 30 + * 31 + * Returns 0 on success. 32 + */ 33 + int bcm63xx_nvram_get_mac_address(u8 *mac); 34 + 35 + #endif /* BCM63XX_NVRAM_H */
-17
arch/mips/include/asm/mach-bcm63xx/board_bcm963xx.h
··· 15 15 #define BCM963XX_NVRAM_OFFSET 0x580 16 16 17 17 /* 18 - * nvram structure 19 - */ 20 - struct bcm963xx_nvram { 21 - u32 version; 22 - u8 reserved1[256]; 23 - u8 name[16]; 24 - u32 main_tp_number; 25 - u32 psi_size; 26 - u32 mac_addr_count; 27 - u8 mac_addr_base[6]; 28 - u8 reserved2[2]; 29 - u32 checksum_old; 30 - u8 reserved3[720]; 31 - u32 checksum_high; 32 - }; 33 - 34 - /* 35 18 * board definition 36 19 */ 37 20 struct board_info {