[PATCH] Pegasus: Add MAC programmability

Previous thread: Pegasus: Bug / Correction (?) by Davide Rizzo on Thursday, August 13, 2009 - 3:11 am. (3 messages)

Next thread: [Iproute2]: failed replacing internal netem qdisc with pfifo by Marcela Maslanova on Thursday, August 13, 2009 - 3:26 am. (1 message)
From: Davide Rizzo
Date: Thursday, August 13, 2009 - 3:10 am

Added capability to set mac address and to program it into EEPROM

Signed-off-by: Davide Rizzo <elpa.rizzo@gmail.com>
---
diff -urNp linux-2.6.30.4/drivers/net/usb/pegasus.c
linux-2.6.30.4.elpa/drivers/net/usb/pegasus.c
--- linux-2.6.30.4/drivers/net/usb/pegasus.c	2009-08-13 07:14:57.000000000 +0200
+++ linux-2.6.30.4.elpa/drivers/net/usb/pegasus.c	2009-08-13
08:39:01.000000000 +0200
@@ -469,8 +467,49 @@ fail:
 		dev_warn(&pegasus->intf->dev, "%s failed\n", __func__);
 	return -ETIMEDOUT;
 }
+
+/* Got from adm 8515 starter kit */
+static const __u16 def_eeprom[] = {
+			  0x8515, 0x0170, 0x0082, 0x0409, 0x0000,
+	0x07a6, 0x8515, 0x100e, 0x202a, 0x380a, 0x0000, 0x0000, 0x0000,
+	0x030e, 0x0041, 0x0044, 0x004d, 0x0074, 0x0065, 0x006b, 0x0000,
+	0x001e, 0x0055, 0x0053, 0x0042, 0x0020, 0x0031, 0x0030, 0x002f,
+	0x032a, 0x0055, 0x0053, 0x0042, 0x0020, 0x0054, 0x006f, 0x0020,
+	0x004c, 0x0041, 0x004e, 0x0020, 0x0043, 0x006f, 0x006e, 0x0076,
+	0x0065, 0x0072, 0x0074, 0x0065, 0x0072, 0x0000, 0x0000, 0x0000,
+	0x030a, 0x0030, 0x0030, 0x0030, 0x0031, 0x0000, 0x0000, 0x0000,
+};
 #endif				/* PEGASUS_WRITE_EEPROM */

+static int pegasus_set_mac_address(struct net_device *netdev, void *p)
+{
+	struct sockaddr *addr = p;
+	pegasus_t *pegasus = (pegasus_t *) netdev_priv(netdev);
+	int i;
+
+	if (netif_running(netdev))
+		return -EBUSY;
+	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+	dbg("%s: Setting MAC address to ", netdev->name);
+	for (i = 0; i < 5; i++)
+		dbg("%02X:", netdev->dev_addr[i]);
+	dbg("%02X\n", netdev->dev_addr[i]);
+	/* Set the IDR registers. */
+	set_registers(pegasus, EthID, 6, netdev->dev_addr);
+#ifdef PEGASUS_WRITE_EEPROM
+	write_eprom_word(pegasus, 0,
+		(netdev->dev_addr[1] << 8) + netdev->dev_addr[0]);
+	write_eprom_word(pegasus, 1,
+		(netdev->dev_addr[3] << 8) + netdev->dev_addr[2]);
+	write_eprom_word(pegasus, 2,
+		(netdev->dev_addr[5] << 8) + netdev->dev_addr[4]);
+	for (i = 0; i < ARRAY_SIZE(def_eeprom); ...
From: petkan
Date: Friday, August 14, 2009 - 10:21 am

Why do you have to write def_eeprom[] to the eeprom along with the new MAC
address?  This may work for 8515 based controllers, but will most likely
break everything else that antedates it.

The set address function should be much smaller/simpler and not writing to
the eeprom in general.




--

From: Davide Rizzo
Date: Friday, August 14, 2009 - 11:18 pm

You're correct.
Because I produce embedded boards with ADM8515 controller, my purpose
was to program eeprom in full, without need to pre-program it before
assemblying the boards.
Writing MAC in eeprom is already protectected by a #ifdef
PEGASUS_WRITE_EEPROM (that should be normally disabled, I agree).
What about protecting the writing of other data with a nested #ifdef
PEGASUS_WRITE_EEPROM_HEADER ? Do you have eeprom datas for other
Pegasus chipsets to include in the source ? Or is there any dedicated
API I don't know about to make this job ?

--

From: Petko Manolov
Date: Sunday, August 16, 2009 - 5:04 am

Nope, i don't recall having the eeprom data.  It is not that important 
anyway.  Apart from permanently storing the MAC address in the eeprom, 
write to it should be avoided.

There's no API i know of.  The easiest way to change driver's behavior is 
using driver parameters via modprobe.


 		Petko


--

Previous thread: Pegasus: Bug / Correction (?) by Davide Rizzo on Thursday, August 13, 2009 - 3:11 am. (3 messages)

Next thread: [Iproute2]: failed replacing internal netem qdisc with pfifo by Marcela Maslanova on Thursday, August 13, 2009 - 3:26 am. (1 message)