From 93596956391157d9ec9103b0c8033d0505b8b102 Mon Sep 17 00:00:00 2001 From: Marcel Ziswiler Date: Wed, 5 Dec 2012 16:20:01 +0100 Subject: net: asix: revise Ethernet MAC address assignment Revise Ethernet MAC address assignment: should now use MAC from EEPROM if set and further handles up to two instances of custom user MACs (2nd one with a 0x100000 offset). This way customer does not have to put EEPROM on a secondary Ethernet on the carrier board and still gets a valid official MAC address from us (e.g. analogous to how we did it on our Protea carrier board). --- drivers/net/usb/asix.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'drivers/net') diff --git a/drivers/net/usb/asix.c b/drivers/net/usb/asix.c index 6f4f9e206a79..3218f52b3a3d 100644 --- a/drivers/net/usb/asix.c +++ b/drivers/net/usb/asix.c @@ -1703,6 +1703,7 @@ static int ax88772b_bind(struct usbnet *dev, struct usb_interface *intf) u8 i; u8 TempPhySelect; bool InternalPhy; + u8 default_asix_mac[ETH_ALEN] = { 0x00, 0x0e, 0xc6, 0x87, 0x72, 0x01 }; axusbnet_get_endpoints(dev,intf); @@ -1783,20 +1784,30 @@ static int ax88772b_bind(struct usbnet *dev, struct usb_interface *intf) ax772b_data->psc = *tmp16 & 0xFF00; /* End of get EEPROM data */ - if (g_usr_mac) { - /* Get user set MAC address */ - memcpy(buf, g_mac_addr, ETH_ALEN); - } else { - /* Get the MAC address from EEPROM */ - memset(buf, 0, ETH_ALEN); - for (i = 0; i < (ETH_ALEN >> 1); i++) { - if ((ret = ax8817x_read_cmd (dev, AX_CMD_READ_EEPROM, - 0x04 + i, 0, 2, (buf + i * 2))) < 0) { - deverr(dev, "read SROM address 04h failed: %d", ret); - goto err_out; - } + /* Get the MAC address from EEPROM */ + memset(buf, 0, ETH_ALEN); + for (i = 0; i < (ETH_ALEN >> 1); i++) { + if ((ret = ax8817x_read_cmd (dev, AX_CMD_READ_EEPROM, + 0x04 + i, 0, 2, (buf + i * 2))) < 0) { + deverr(dev, "read SROM address 04h failed: %d", ret); + goto err_out; } } + + /* Check for default ASIX MAC (e.g. 00:0e:c6:87:72:01) in case of no EEPROM being present */ + if (!memcmp(buf, default_asix_mac, ETH_ALEN)) { + if (g_usr_mac && (g_usr_mac < 3)) { + /* Get user set MAC address */ + if (g_usr_mac == 2) { + /* 0x100000 offset for 2nd Ethernet MAC */ + g_mac_addr[3] += 0x10; + if (g_mac_addr[3] < 0x10) + devwarn(dev, "MAC address byte 3 (0x%02x) wrap around", g_mac_addr[3]); + } + memcpy(buf, g_mac_addr, ETH_ALEN); + g_usr_mac++; + } else devwarn(dev, "using default ASIX MAC"); + } memcpy(dev->net->dev_addr, buf, ETH_ALEN); /* Set the MAC address */ -- cgit v1.2.3