Fixes the MAC address handling on avila NPE on startup
Added support for changing the mac address at runtime

Replaces/based-on 740-avila_loft_mac_platform.patch for 2.6.21

Signed-off-by: Harald Schioeberg <[EMAIL PROTECTED]>

Index: target/linux/ixp4xx/patches-2.6.23/203-npe_macaddress.patch
===================================================================
--- target/linux/ixp4xx/patches-2.6.23/203-npe_macaddress.patch	(revision 0)
+++ target/linux/ixp4xx/patches-2.6.23/203-npe_macaddress.patch	(revision 0)
@@ -0,0 +1,128 @@
+diff -r -u linux-2.6.23.12/arch/arm/mach-ixp4xx/avila-setup.c ../../../../trunk/build_dir/linux-ixp4xx_generic/linux-2.6.23.12/arch/arm/mach-ixp4xx/avila-setup.c
+--- linux-2.6.23.12/arch/arm/mach-ixp4xx/avila-setup.c	2008-01-04 01:28:24.134925761 +0100
++++ ../../../../trunk/build_dir/linux-ixp4xx_generic/linux-2.6.23.12/arch/arm/mach-ixp4xx/avila-setup.c	2008-01-04 01:23:27.874042817 +0100
+@@ -14,10 +14,18 @@
+ #include <linux/kernel.h>
+ #include <linux/init.h>
+ #include <linux/device.h>
++#include <linux/if_ether.h>
++#include <linux/socket.h>
++#include <linux/netdevice.h>
+ #include <linux/serial.h>
+ #include <linux/tty.h>
+ #include <linux/serial_8250.h>
+ #include <linux/slab.h>
++#ifdef CONFIG_SENSORS_EEPROM
++# include <linux/i2c.h>
++# include <linux/eeprom.h>
++#endif
++
+ #include <linux/i2c-gpio.h>
+ 
+ #include <asm/types.h>
+@@ -194,9 +202,48 @@
+     t->hdr.size = 0;
+ }
+ 
++#ifdef CONFIG_SENSORS_EEPROM
++static int loft_eeprom_do(struct notifier_block *self, unsigned long event, void *t)
++{
++       struct eeprom_data *data = t;
++       struct sockaddr address;
++       struct net_device * netdev ;
++
++       char macs[12];
++
++       /* The MACs are the first 12 bytes in the eeprom at address 0x51 */
++       if (event == EEPROM_REGISTER && data->client.addr == 0x51) {
++               data->attr->read(&data->client.dev.kobj, data->attr, macs, 0, 12);
++		/*eth0*/
++		/* using dev_get_by_name here is really ugly and can cause
++ 		* confusion if other ethernet devices are present. FIXME */
++		
++		memcpy(address.sa_data, macs, ETH_ALEN);
++               	memcpy(&avila_plat_eth[0].hwaddr, macs, ETH_ALEN);
++		if ( (netdev = dev_get_by_name("eth0")) )
++			netdev->set_mac_address(netdev, &address);
++
++                /*same for eth1*/
++	 	memcpy(address.sa_data, macs + ETH_ALEN, ETH_ALEN);
++	       memcpy(&avila_plat_eth[1].hwaddr, macs + ETH_ALEN, ETH_ALEN);
++		if ( (netdev = dev_get_by_name("eth1")) )
++			netdev->set_mac_address(netdev, &address);
++       }
++
++       return NOTIFY_DONE;
++}
++
++static struct notifier_block loft_eeprom_notifier = {
++       .notifier_call = loft_eeprom_do
++};
++#endif
++
+ static void __init avila_init(void)
+ {
+ 	ixp4xx_sys_init();
++#ifdef CONFIG_SENSORS_EEPROM
++       register_eeprom_notifier(&loft_eeprom_notifier);
++#endif
+ 
+ 	avila_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
+ 	avila_flash_resource.end =
+
+diff -r -u linux-2.6.23.12/drivers/net/arm/ixp4xx_eth.c ../../../../trunk/build_dir/linux-ixp4xx_generic/linux-2.6.23.12/drivers/net/arm/ixp4xx_eth.c
+--- linux-2.6.23.12/drivers/net/arm/ixp4xx_eth.c	2008-01-04 01:28:24.418941946 +0100
++++ ../../../../trunk/build_dir/linux-ixp4xx_generic/linux-2.6.23.12/drivers/net/arm/ixp4xx_eth.c	2008-01-04 01:08:28.934815190 +0100
+@@ -1113,6 +1113,35 @@
+ 	return 0;
+ }
+ 
++static int set_mac_address(struct net_device *dev, 
++	void * addr) {
++
++	struct port *port = netdev_priv(dev);
++	struct msg msg;
++	struct sockaddr *address = addr;
++	
++	if (!is_valid_ether_addr(address->sa_data))
++		return -EADDRNOTAVAIL;
++	  
++        memcpy(dev->dev_addr, address->sa_data, dev->addr_len);		
++
++	msg.cmd = NPE_EDB_SETPORTADDRESS;
++	msg.eth_id = PHYSICAL_ID(port->id);
++	msg.byte2 = dev->dev_addr[0];
++	msg.byte3 = dev->dev_addr[1];
++	msg.byte4 = dev->dev_addr[2];
++	msg.byte5 = dev->dev_addr[3];
++	msg.byte6 = dev->dev_addr[4];
++	msg.byte7 = dev->dev_addr[5];
++	if (npe_send_message(port->npe, &msg, "ETH_SET_MAC"))
++		return -EIO;
++
++	printk(KERN_INFO "new mac: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
++	dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], 
++	dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
++	return 0;
++}
++
+ static int __devinit eth_init_one(struct platform_device *pdev)
+ {
+ 	struct port *port;
+@@ -1155,6 +1184,7 @@
+ 	dev->get_stats = eth_stats;
+ 	dev->do_ioctl = eth_ioctl;
+ 	dev->set_multicast_list = eth_set_mcast_list;
++	dev->set_mac_address = set_mac_address;
+ 	dev->weight = 16;
+ 	dev->tx_queue_len = 100;
+ 
+@@ -1177,6 +1207,9 @@
+ 	port->plat = plat;
+ 	npe_port_tab[NPE_ID(port->id)] = port;
+ 	memcpy(dev->dev_addr, plat->hwaddr, ETH_ALEN);
++	printk(KERN_INFO "copied mac: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
++	dev->dev_addr[0],dev->dev_addr[1],dev->dev_addr[2],
++	dev->dev_addr[3],dev->dev_addr[4],dev->dev_addr[5]);
+ 
+ 	platform_set_drvdata(pdev, dev);
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
http://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to