summaryrefslogtreecommitdiff
path: root/packages/linux/ixp4xx-kernel/2.6.16/92-nslu2-mac.patch
blob: 1dd8e0eb61fa80daa49f0cfc738fdd9428ed1106 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 arch/arm/mach-ixp4xx/nslu2-setup.c |   62 +++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

--- linux-ixp4xx.orig/arch/arm/mach-ixp4xx/nslu2-setup.c	2006-03-27 14:42:07.000000000 +0200
+++ linux-ixp4xx/arch/arm/mach-ixp4xx/nslu2-setup.c	2006-03-27 14:45:45.000000000 +0200
@@ -16,6 +16,9 @@
 #include <linux/kernel.h>
 #include <linux/serial.h>
 #include <linux/serial_8250.h>
+#include <linux/mtd/mtd.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
@@ -117,6 +120,59 @@ static void nslu2_power_off(void)
 	gpio_line_set(NSLU2_PO_GPIO, IXP4XX_GPIO_HIGH);
 }
 
+/*
+ * When the RedBoot config partition is added the MAC address is read from
+ * it.
+ */
+static struct sockaddr mac;
+
+static void nslu2_flash_add(struct mtd_info *mtd) {
+	if (strcmp(mtd->name, "RedBoot") == 0) {
+		size_t retlen;
+		int err;
+		/* the mac addr is at a known offset */
+		err = mtd->read(mtd, 0x3FFD8, 6, &retlen, (u8 *) &mac.sa_data);
+		if (err != 0 || retlen != 6)
+			printk(KERN_ERR "nslu2: mac addr read failed\n");
+		else
+			printk(KERN_INFO
+				"nslu2: mac %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
+				mac.sa_data[0], mac.sa_data[1], mac.sa_data[2],
+				mac.sa_data[3], mac.sa_data[4], mac.sa_data[5]);
+	}
+}
+
+static void nslu2_flash_remove(struct mtd_info *mtd) {
+}
+
+static struct mtd_notifier nslu2_flash_notifier = {
+	.add = nslu2_flash_add,
+	.remove = nslu2_flash_remove,
+};
+
+
+static int nslu2_netdev_event(struct notifier_block *this,
+				unsigned long event, void *ptr)
+{
+	struct net_device *dev = ptr;
+
+	/* identify the ixp4xx eth, port 1 */
+	if (dev->dev_addr[1] != 0x02 || dev->dev_addr[2] != 0xB3
+		|| dev->dev_addr[5] != 0x01)
+		return NOTIFY_DONE;
+
+	if (event == NETDEV_REGISTER && is_valid_ether_addr(mac.sa_data)) {
+		mac.sa_family = dev->type;
+		dev_set_mac_address(dev, &mac);
+	}
+
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block nslu2_netdev_notifier = {
+	.notifier_call = nslu2_netdev_event,
+};
+
 static void __init nslu2_init(void)
 {
 	/* The NSLU2 has a 33MHz crystal on board - 1.01% different
@@ -124,6 +180,12 @@ static void __init nslu2_init(void)
 	 */
 	ixp4xx_set_board_tick_rate(66000000);
 
+	/* The flash has an ethernet MAC embedded in it which we need,
+	 * that is all this notifier does.
+	 */
+	register_mtd_user(&nslu2_flash_notifier);
+	register_netdevice_notifier(&nslu2_netdev_notifier);
+
 	ixp4xx_sys_init();
 
 	nslu2_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);