diff options
author | Gabor Juhos <juhosg@openwrt.org> | 2008-08-20 17:20:58 +0000 |
---|---|---|
committer | Gabor Juhos <juhosg@openwrt.org> | 2008-08-20 17:20:58 +0000 |
commit | d9b755b3dc4f9121ab70b9d816ce813f6038ad6b (patch) | |
tree | 52986b3e2a2d38500b4502251cca8418d515faec /target/linux | |
parent | 6922a3692d36d41b9d907ac3b13df075c5bf50db (diff) | |
download | upstream-d9b755b3dc4f9121ab70b9d816ce813f6038ad6b.tar.gz upstream-d9b755b3dc4f9121ab70b9d816ce813f6038ad6b.tar.bz2 upstream-d9b755b3dc4f9121ab70b9d816ce813f6038ad6b.zip |
load the mac address from flash where it is possible
SVN-Revision: 12357
Diffstat (limited to 'target/linux')
19 files changed, 200 insertions, 33 deletions
diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/cellvision/cellvision.c b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/cellvision/cellvision.c index 2b90ce16d0..15aa5feb96 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/cellvision/cellvision.c +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/cellvision/cellvision.c @@ -11,9 +11,14 @@ #include "cellvision.h" +#include <prom/admboot.h> + #define CELLVISION_GPIO_FLASH_A20 ADM5120_GPIO_PIN5 #define CELLVISION_GPIO_DEV_MASK (1 << CELLVISION_GPIO_FLASH_A20) +#define CELLVISION_CONFIG_OFFSET 0x8000 +#define CELLVISION_CONFIG_SIZE 0x1000 + #ifdef CONFIG_MTD_PARTITIONS static struct mtd_partition cas6xx_partitions[] = { { @@ -84,6 +89,20 @@ static void __init cellvision_flash_setup(void) adm5120_add_device_flash(0); } +void __init cellvision_mac_setup(void) +{ + u8 mac_base[6]; + int err; + + err = admboot_get_mac_base(CELLVISION_CONFIG_OFFSET, + CELLVISION_CONFIG_SIZE, mac_base); + + if ((err) || !is_valid_ether_addr(mac_base)) + random_ether_addr(mac_base); + + adm5120_setup_eth_macs(mac_base); +} + void __init cas6xx_flash_setup(void) { #ifdef CONFIG_MTD_PARTITIONS @@ -118,6 +137,8 @@ ADM5120_BOARD(MACH_ADM5120_CAS670, "Cellvision CAS-670/670W", cas6xx_setup); void __init cas7xx_setup(void) { cas7xx_flash_setup(); + + cellvision_mac_setup(); adm5120_add_device_switch(1, NULL); } diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/cellvision/cellvision.h b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/cellvision/cellvision.h index c7c6a1e19f..70742e9b59 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/cellvision/cellvision.h +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/cellvision/cellvision.h @@ -12,6 +12,7 @@ #include <linux/kernel.h> #include <linux/init.h> #include <linux/gpio.h> +#include <linux/etherdevice.h> #include <asm/bootinfo.h> @@ -20,6 +21,8 @@ #include <asm/mach-adm5120/adm5120_platform.h> #include <asm/mach-adm5120/adm5120_irq.h> +extern void cellvision_mac_setup(void) __init; + extern void cas6xx_flash_setup(void) __init; extern void cas7xx_flash_setup(void) __init; extern void cas6xx_setup(void) __init; diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/cellvision/nfs-101.c b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/cellvision/nfs-101.c index efd4e5758c..700919ca26 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/cellvision/nfs-101.c +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/cellvision/nfs-101.c @@ -18,6 +18,8 @@ static u8 nfs101_vlans[6] __initdata = { /* TODO: not tested */ static void __init nfs101_setup(void) { cas6xx_flash_setup(); + + cellvision_mac_setup(); adm5120_add_device_switch(5, nfs101_vlans); } diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/common/platform.c b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/common/platform.c index e58560e008..5cae2023fd 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/common/platform.c +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/common/platform.c @@ -50,6 +50,26 @@ unsigned char adm5120_eth_vlans[6] = { EXPORT_SYMBOL_GPL(adm5120_eth_vlans); #endif +void __init adm5120_setup_eth_macs(u8 *mac_base) +{ + u32 t; + int i, j; + + t = ((u32) mac_base[3] << 16) | ((u32) mac_base[4] << 8) + | ((u32) mac_base[5]); + + for (i = 0; i < ARRAY_SIZE(adm5120_eth_macs); i++) { + for (j = 0; j < 3; j++) + adm5120_eth_macs[i][j] = mac_base[j]; + + adm5120_eth_macs[i][3] = (t >> 16) & 0xff; + adm5120_eth_macs[i][4] = (t >> 8) & 0xff; + adm5120_eth_macs[i][5] = t & 0xff; + + t++; + } +} + /* * Built-in ethernet switch */ diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/compex/compex.c b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/compex/compex.c index 10120d6226..81157812bb 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/compex/compex.c +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/compex/compex.c @@ -9,21 +9,10 @@ * */ -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/gpio.h> - -#include <asm/bootinfo.h> - -#include <asm/mach-adm5120/adm5120_info.h> -#include <asm/mach-adm5120/adm5120_board.h> -#include <asm/mach-adm5120/adm5120_platform.h> -#include <asm/mach-adm5120/adm5120_irq.h> +#include "compex.h" #include <asm/mach-adm5120/prom/myloader.h> -#include "compex.h" - #define COMPEX_GPIO_DEV_MASK (1 << ADM5120_GPIO_PIN5) static void switch_bank_gpio5(unsigned bank) @@ -40,14 +29,22 @@ static void switch_bank_gpio5(unsigned bank) void __init compex_mac_setup(void) { - int i, j; - - if (!myloader_present()) - return; - - for (i = 0; i < 6; i++) - for (j = 0; j < 6; j++) - adm5120_eth_macs[i][j] = myloader_info.macs[i][j]; + if (myloader_present()) { + int i; + + for (i = 0; i < 6; i++) { + if (is_valid_ether_addr(myloader_info.macs[i])) + memcpy(myloader_info.macs[i], + adm5120_eth_macs[i], ETH_ALEN); + else + random_ether_addr(adm5120_eth_macs[i]); + } + } else { + u8 mac[ETH_ALEN]; + + random_ether_addr(mac); + adm5120_setup_eth_macs(mac); + } } void __init compex_generic_setup(void) diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/compex/compex.h b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/compex/compex.h index ac2fb6939e..739a90d023 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/compex/compex.h +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/compex/compex.h @@ -11,9 +11,10 @@ #include <linux/kernel.h> #include <linux/init.h> +#include <linux/gpio.h> +#include <linux/etherdevice.h> #include <asm/bootinfo.h> -#include <linux/gpio.h> #include <asm/mach-adm5120/adm5120_info.h> #include <asm/mach-adm5120/adm5120_board.h> diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/edimax/br-61xx.c b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/edimax/br-61xx.c index 33bff87062..e784713288 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/edimax/br-61xx.c +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/edimax/br-61xx.c @@ -11,8 +11,13 @@ #include "br-61xx.h" +#include <prom/admboot.h> + #define BR61XX_GPIO_DEV_MASK 0 +#define BR61XX_CONFIG_OFFSET 0x8000 +#define BR61XX_CONFIG_SIZE 0x1000 + #ifdef CONFIG_MTD_PARTITIONS static struct mtd_partition br61xx_partitions[] = { { @@ -46,6 +51,20 @@ static u8 br61xx_vlans[6] __initdata = { 0x41, 0x42, 0x44, 0x48, 0x50, 0x00 }; +static void __init br61xx_mac_setup(void) +{ + u8 mac_base[6]; + int err; + + err = admboot_get_mac_base(BR61XX_CONFIG_OFFSET, + BR61XX_CONFIG_SIZE, mac_base); + + if ((err) || !is_valid_ether_addr(mac_base)) + random_ether_addr(mac_base); + + adm5120_setup_eth_macs(mac_base); +} + void __init br61xx_generic_setup(void) { @@ -56,9 +75,10 @@ void __init br61xx_generic_setup(void) adm5120_add_device_flash(0); adm5120_add_device_gpio(BR61XX_GPIO_DEV_MASK); + adm5120_add_device_switch(5, br61xx_vlans); adm5120_add_device_gpio_buttons(ARRAY_SIZE(br61xx_gpio_buttons), br61xx_gpio_buttons); - /* TODO: setup mac addresses */ + br61xx_mac_setup(); } diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/edimax/br-61xx.h b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/edimax/br-61xx.h index fff4789770..d7efda32d1 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/edimax/br-61xx.h +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/edimax/br-61xx.h @@ -12,6 +12,7 @@ #include <linux/kernel.h> #include <linux/init.h> #include <linux/gpio.h> +#include <linux/etherdevice.h> #include <asm/bootinfo.h> diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/infineon/infineon.c b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/infineon/infineon.c index 9d898b7ac0..bbe8c7195a 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/infineon/infineon.c +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/infineon/infineon.c @@ -11,6 +11,11 @@ #include "infineon.h" +#include <prom/admboot.h> + +#define EASY_CONFIG_OFFSET 0x10000 +#define EASY_CONFIG_SIZE 0x1000 + #ifdef CONFIG_MTD_PARTITIONS static struct mtd_partition easy_partitions[] = { { @@ -30,6 +35,20 @@ static struct mtd_partition easy_partitions[] = { }; #endif /* CONFIG_MTD_PARTITIONS */ +static __init void easy_setup_mac(void) +{ + u8 mac_base[6]; + int err; + + err = admboot_get_mac_base(EASY_CONFIG_OFFSET, + EASY_CONFIG_SIZE, mac_base); + + if ((err) || !is_valid_ether_addr(mac_base)) + random_ether_addr(mac_base); + + adm5120_setup_eth_macs(mac_base); +} + static void switch_bank_gpio3(unsigned bank) { switch (bank) { @@ -55,6 +74,8 @@ void __init easy_setup_pqfp(void) #endif /* CONFIG_MTD_PARTITIONS */ adm5120_add_device_flash(0); + + easy_setup_mac(); } static void switch_bank_gpio5(unsigned bank) @@ -82,4 +103,6 @@ void __init easy_setup_bga(void) #endif /* CONFIG_MTD_PARTITIONS */ adm5120_add_device_flash(0); + + easy_setup_mac(); } diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/infineon/infineon.h b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/infineon/infineon.h index 1d96cc1f13..f3b28e0880 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/infineon/infineon.h +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/infineon/infineon.h @@ -11,9 +11,10 @@ #include <linux/kernel.h> #include <linux/init.h> +#include <linux/gpio.h> +#include <linux/etherdevice.h> #include <asm/bootinfo.h> -#include <linux/gpio.h> #include <asm/mach-adm5120/adm5120_defs.h> #include <asm/mach-adm5120/adm5120_irq.h> diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/mikrotik/rb-1xx.c b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/mikrotik/rb-1xx.c index dd506aa1cc..8edca5bcb1 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/mikrotik/rb-1xx.c +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/mikrotik/rb-1xx.c @@ -101,15 +101,13 @@ struct gpio_button rb1xx_gpio_buttons[] __initdata = { static void __init rb1xx_mac_setup(void) { - int i, j; + if (rb_hs.mac_base != NULL && is_valid_ether_addr(rb_hs.mac_base)) { + adm5120_setup_eth_macs(rb_hs.mac_base); + } else { + u8 mac[ETH_ALEN]; - if (!rb_hs.mac_base) - return; - - for (i = 0; i < 6; i++) { - for (j = 0; j < 5; j++) - adm5120_eth_macs[i][j] = rb_hs.mac_base[j]; - adm5120_eth_macs[i][5] = rb_hs.mac_base[5]+i; + random_ether_addr(mac); + adm5120_setup_eth_macs(mac); } } diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/mikrotik/rb-1xx.h b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/mikrotik/rb-1xx.h index ebc514c655..d5acef028e 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/mikrotik/rb-1xx.h +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/mikrotik/rb-1xx.h @@ -13,6 +13,7 @@ #include <linux/init.h> #include <linux/delay.h> #include <linux/gpio.h> +#include <linux/etherdevice.h> #include <asm/bootinfo.h> diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/prom/Makefile b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/prom/Makefile index d844b600f3..650be40779 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/prom/Makefile +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/prom/Makefile @@ -2,6 +2,7 @@ # Makefile for the ADMtek ADM5120 SoC specific parts of the kernel # +lib-y += admboot.o lib-y += bootbase.o lib-y += cfe.o lib-y += generic.o diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/prom/admboot.c b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/prom/admboot.c new file mode 100644 index 0000000000..5d436f62f6 --- /dev/null +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/prom/admboot.c @@ -0,0 +1,46 @@ +/* + * ADMBoot specific prom routines + * + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + */ + +#include <linux/types.h> +#include <linux/init.h> +#include <linux/errno.h> + +#include <asm/addrspace.h> +#include <asm/byteorder.h> + +#include <asm/mach-adm5120/adm5120_defs.h> +#include <prom/admboot.h> +#include "prom_read.h" + +#define ADMBOOT_MAGIC_MAC_BASE 0x636D676D /* 'mgmc' */ + +int __init admboot_get_mac_base(u32 offset, u32 len, u8 *mac) +{ + u8 *cfg; + int i; + + cfg = (u8 *) KSEG1ADDR(ADM5120_SRAM0_BASE + offset); + for (i = 0; i < len; i += 4) { + u32 magic; + + magic = prom_read_le32(cfg + i); + if (magic == ADMBOOT_MAGIC_MAC_BASE) { + int j; + + for (j = 0; j < 6; j++) + mac[j] = cfg[i + 4 + j]; + + return 0; + } + } + + return -ENXIO; +} diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/prom/bootbase.c b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/prom/bootbase.c index 23f8e14625..b6a94ff46a 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/prom/bootbase.c +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/prom/bootbase.c @@ -53,6 +53,14 @@ static inline u32 bootbase_get_bootext_addr(void) return prom_read_be32(&board_info->bootext_addr); } +static inline void bootbase_get_mac(u8 *mac) +{ + int i; + + for (i = 0; i < 6; i++) + mac[i] = board_info->mac[i]; +} + static inline u16 bootbase_get_vendor_id(void) { #define CHECK_VENDOR(n) (strnicmp(board_info->vendor, (n), strlen(n)) == 0) @@ -102,6 +110,7 @@ int __init bootbase_present(void) bootbase_info.vendor_id = bootbase_get_vendor_id(); bootbase_info.board_id = bootbase_get_board_id(); + bootbase_get_mac(bootbase_info.mac); bootbase_found = 1; diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/zyxel/p-33x.c b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/zyxel/p-33x.c index f27a80c158..2a83c9b2a4 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/zyxel/p-33x.c +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/zyxel/p-33x.c @@ -11,6 +11,8 @@ #include "p-33x.h" +#include <prom/zynos.h> + #define P33X_GPIO_FLASH_A20 ADM5120_GPIO_PIN5 #define P33X_GPIO_DEV_MASK (1 << P33X_GPIO_FLASH_A20) @@ -76,6 +78,8 @@ void __init p33x_generic_setup(void) adm5120_add_device_flash(0); adm5120_add_device_gpio(P33X_GPIO_DEV_MASK); + + adm5120_setup_eth_macs(bootbase_info.mac); adm5120_add_device_switch(5, p33x_vlans); adm5120_pci_set_irq_map(ARRAY_SIZE(p33x_pci_irqs), p33x_pci_irqs); diff --git a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/zyxel/p-33x.h b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/zyxel/p-33x.h index faff3bd729..4817e81050 100644 --- a/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/zyxel/p-33x.h +++ b/target/linux/adm5120/files-2.6.26/arch/mips/adm5120/zyxel/p-33x.h @@ -11,12 +11,12 @@ #include <linux/kernel.h> #include <linux/init.h> +#include <linux/gpio.h> #include <asm/bootinfo.h> -#include <linux/gpio.h> #include <asm/mach-adm5120/adm5120_board.h> #include <asm/mach-adm5120/adm5120_platform.h> #include <asm/mach-adm5120/adm5120_irq.h> -extern void p33x_generic_setup(void) __init;
\ No newline at end of file +extern void p33x_generic_setup(void) __init; diff --git a/target/linux/adm5120/files-2.6.26/include/asm-mips/mach-adm5120/adm5120_platform.h b/target/linux/adm5120/files-2.6.26/include/asm-mips/mach-adm5120/adm5120_platform.h index 24f38e3994..9d2e430cd8 100644 --- a/target/linux/adm5120/files-2.6.26/include/asm-mips/mach-adm5120/adm5120_platform.h +++ b/target/linux/adm5120/files-2.6.26/include/asm-mips/mach-adm5120/adm5120_platform.h @@ -57,6 +57,8 @@ static inline void adm5120_pci_set_irq_map(unsigned int nr_irqs, } #endif +extern void adm5120_setup_eth_macs(u8 *mac_base) __init; + extern struct adm5120_flash_platform_data adm5120_flash0_data; extern struct adm5120_flash_platform_data adm5120_flash1_data; diff --git a/target/linux/adm5120/files-2.6.26/include/asm-mips/mach-adm5120/prom/admboot.h b/target/linux/adm5120/files-2.6.26/include/asm-mips/mach-adm5120/prom/admboot.h new file mode 100644 index 0000000000..fa42bf7148 --- /dev/null +++ b/target/linux/adm5120/files-2.6.26/include/asm-mips/mach-adm5120/prom/admboot.h @@ -0,0 +1,17 @@ +/* + * ADMBoot specific definitions + * + * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + */ + +#ifndef _ADMBOOT_H +#define _ADMBOOT_H + +extern int admboot_get_mac_base(u32 offset, u32 len, u8 *mac) __init; + +#endif /* _ADMBOOT_H */ |