[PATCH 2/2] smsc95xx: allow to re-use MAC address already programmed

From: Peter Meerwald
Date: Wed Feb 08 2012 - 06:09:30 EST


From: Peter Meerwald <p.meerwald@xxxxxxxxxxxxxxxxxx>

patch adds a module parameter which allows to keep the MAC address already
set (e.g. by the boot loader) if it is valid (otherwise the MAC address is read
from an optional EEPROM or randomly generated)

tested on beagleboard-xm

Signed-off-by: Peter Meerwald <p.meerwald@xxxxxxxxxxxxxxxxxx>

---
drivers/net/usb/smsc95xx.c | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index b7b2326..5545a60 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -67,6 +67,10 @@ static bool leds_off = false;
module_param(leds_off, bool, 0644);
MODULE_PARM_DESC(leds_off, "Turn off NIC LEDs");

+static bool keep_mac = false;
+module_param(keep_mac, bool, 0644);
+MODULE_PARM_DESC(keep_mac, "Keep MAC address set by boot loader if available");
+
static int smsc95xx_read_reg(struct usbnet *dev, u32 index, u32 *data)
{
u32 *buf = kmalloc(4, GFP_KERNEL);
@@ -607,6 +611,21 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)

static void smsc95xx_init_mac_address(struct usbnet *dev)
{
+ if (keep_mac) {
+ u32 addr_lo, addr_hi;
+ int ret = smsc95xx_read_reg(dev, ADDRL, &addr_lo);
+ if (ret < 0) {
+ netdev_warn(dev->net, "Failed to read ADDRL: %d\n", ret);
+ }
+ ret = smsc95xx_read_reg(dev, ADDRH, &addr_hi);
+
+ if (is_valid_ether_addr(dev->net->dev_addr)) {
+ /* MAC values are valid so use them */
+ netif_dbg(dev, ifup, dev->net, "MAC address already configured\n");
+ return;
+ }
+ }
+
/* try reading mac address from EEPROM */
if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
dev->net->dev_addr) == 0) {
--
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/