load the mac address from flash where it is possible
authorGabor Juhos <juhosg@openwrt.org>
Wed, 20 Aug 2008 17:20:58 +0000 (17:20 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Wed, 20 Aug 2008 17:20:58 +0000 (17:20 +0000)
SVN-Revision: 12357

19 files changed:
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/cellvision/cellvision.c
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/cellvision/cellvision.h
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/cellvision/nfs-101.c
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/common/platform.c
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/compex/compex.c
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/compex/compex.h
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/edimax/br-61xx.c
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/edimax/br-61xx.h
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/infineon/infineon.c
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/infineon/infineon.h
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/mikrotik/rb-1xx.c
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/mikrotik/rb-1xx.h
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/prom/Makefile
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/prom/admboot.c [new file with mode: 0644]
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/prom/bootbase.c
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/zyxel/p-33x.c
target/linux/adm5120/files-2.6.26/arch/mips/adm5120/zyxel/p-33x.h
target/linux/adm5120/files-2.6.26/include/asm-mips/mach-adm5120/adm5120_platform.h
target/linux/adm5120/files-2.6.26/include/asm-mips/mach-adm5120/prom/admboot.h [new file with mode: 0644]

index 2b90ce16d0cd51b4172a2c80fb4de416a6a2c7e0..15aa5feb96705c9b0b73819a4ff42a9dd4c533af 100644 (file)
 
 #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);
 }
 
index c7c6a1e19f6b1d5c19f61397dd4d4a6f23fb2d08..70742e9b5956c0f054bf8f903a7b3206871be5e7 100644 (file)
@@ -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;
index efd4e5758c3e644fb8f23179fb1b6548333a4665..700919ca26758764778a00c4ad1af298deaed236 100644 (file)
@@ -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);
 }
 
index e58560e0083a38efe519a4144256f7ba9651b790..5cae2023fd15dc246ced6cef12f4824df40d72cd 100644 (file)
@@ -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
  */
index 10120d6226d4b7e41edc6ab3b59e45e377a5c6ce..81157812bbbe6875781a7b66693fac5324688d89 100644 (file)
@@ -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)
index ac2fb6939e2893293b251a99ba53c38e629af991..739a90d02347e8ba9f0a97d58711a4a41abe3cb4 100644 (file)
 
 #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>
index 33bff87062bbee7d313e83511891b5f9039967e1..e784713288f23cf9cee008434471ec660b966c91 100644 (file)
 
 #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();
 }
index fff4789770309531c77f59ecfd3d21baf8d8c535..d7efda32d1140dde5002f0b0b6f4a905de1c3aa5 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/gpio.h>
+#include <linux/etherdevice.h>
 
 #include <asm/bootinfo.h>
 
index 9d898b7ac094b6da80564a749566ecdd0a8270c6..bbe8c7195a8b44cbe25e7260566a76954a686572 100644 (file)
 
 #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();
 }
index 1d96cc1f13133909e5704db5f68addbfd4eb8cf3..f3b28e08806e05b0201d1605bfa63d76b67ef5e9 100644 (file)
 
 #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>
index dd506aa1cc2f6f6165aaacef58c2364f3036520e..8edca5bcb14633801a3d3f1797ffdc6643c1611c 100644 (file)
@@ -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);
        }
 }
 
index ebc514c655361d5d4de9ff8a918a50f22f6455f3..d5acef028e782629266762c9ba0b13fd24c0a8e3 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/gpio.h>
+#include <linux/etherdevice.h>
 
 #include <asm/bootinfo.h>
 
index d844b600f3ab639bc711cbc95a0568357332a171..650be40779445336b63c220a1371140812c6aa79 100644 (file)
@@ -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 (file)
index 0000000..5d436f6
--- /dev/null
@@ -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;
+}
index 23f8e14625b4b515b67df4b6ca84148e046b2db8..b6a94ff46a12b1988b5113de49b487e538d56717 100644 (file)
@@ -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;
 
index f27a80c1588780dd63eb7642749c597bce71cebb..2a83c9b2a46181a98f5552a00a3411c70ea51253 100644 (file)
@@ -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);
index faff3bd7298a96cb2546f1488eba7a2c0a2f8f11..4817e810507fcc386d4680f0c25687e7988c7952 100644 (file)
 
 #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;
index 24f38e39946dc68bbbacdea1edb6ac94965f4782..9d2e430cd8eba8f0167a56af56328c1fd972af9a 100644 (file)
@@ -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 (file)
index 0000000..fa42bf7
--- /dev/null
@@ -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 */