[realtek] Implementing set_mac_address for the rtl8139 driver?

Donald Becker becker@scyld.com
Wed, 3 Jan 2001 23:34:24 -0500 (EST)


On Wed, 3 Jan 2001, Ben Greear wrote:

> After poking around in the 8139 driver included with linux 2.4.prerelease,
> and the one on scyld.com, I've come to the conclusion that there is
> absolutely no way that ifconfig can set the mac_address on the
> interface correctly.  The reason seems to be that the driver
> does not set it's own method at dev->set_mac_address, so the default
> is used, which just updates the in-memory net_device structure, and
> does nothing to tell the actual NIC what's goin on....

The key is that dev->dev_addr[] can only be modified when the interface is
stopped.
Here is the generic set method in drivers/net/net_init.c.
Note the check for dev->start.
____
static int eth_mac_addr(struct device *dev, void *p)
{
	struct sockaddr *addr=p;
	if(dev->start)
		return -EBUSY;
	memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
	return 0;
}
____

Properly written Ethernet drivers always copy dev->dev_addr[] to the NIC at
every open() call.  Here is the code from rtl8129_open()

	outl(cpu_to_le32(*(u32*)(dev->dev_addr + 0)), ioaddr + MAC0 + 0);
	outl(cpu_to_le32(*(u32*)(dev->dev_addr + 4)), ioaddr + MAC0 + 4);

This is how 'ifconfig hw ether aa:bb:cc:dd:ee:ff' works.

Donald Becker				becker@scyld.com
Scyld Computing Corporation		http://www.scyld.com
410 Severn Ave. Suite 210		Second Generation Beowulf Clusters
Annapolis MD 21403			410-990-9993