Skip to content

Commit c489565

Browse files
arndbdavem330
authored andcommitted
net/smscx5xx: use the device tree for mac address
This takes the MAC address for smsc75xx/smsc95xx USB network devices from a the device tree. This is required to get a usable persistent address on the popular beagleboard, whose hardware designers accidentally forgot that an ethernet device really requires an a MAC address to be functional. The Raspberry Pi also ships smsc9514 without a serial EEPROM, stores the MAC address in ROM accessible via VC4 firmware. The smsc75xx and smsc95xx drivers are just two copies of the same code, so better fix both. [lkundrak@v3.sk: updated to use of_get_property() as per suggestion from Arnd, reworded the message and comments a bit] Tested-by: Lubomir Rintel <lkundrak@v3.sk> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 90e5d0d commit c489565

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

drivers/net/usb/smsc75xx.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/crc32.h>
3030
#include <linux/usb/usbnet.h>
3131
#include <linux/slab.h>
32+
#include <linux/of_net.h>
3233
#include "smsc75xx.h"
3334

3435
#define SMSC_CHIPNAME "smsc75xx"
@@ -761,6 +762,15 @@ static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
761762

762763
static void smsc75xx_init_mac_address(struct usbnet *dev)
763764
{
765+
const u8 *mac_addr;
766+
767+
/* maybe the boot loader passed the MAC address in devicetree */
768+
mac_addr = of_get_mac_address(dev->udev->dev.of_node);
769+
if (mac_addr) {
770+
memcpy(dev->net->dev_addr, mac_addr, ETH_ALEN);
771+
return;
772+
}
773+
764774
/* try reading mac address from EEPROM */
765775
if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
766776
dev->net->dev_addr) == 0) {
@@ -772,7 +782,7 @@ static void smsc75xx_init_mac_address(struct usbnet *dev)
772782
}
773783
}
774784

775-
/* no eeprom, or eeprom values are invalid. generate random MAC */
785+
/* no useful static MAC address found. generate a random one */
776786
eth_hw_addr_random(dev->net);
777787
netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
778788
}

drivers/net/usb/smsc95xx.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/crc32.h>
3030
#include <linux/usb/usbnet.h>
3131
#include <linux/slab.h>
32+
#include <linux/of_net.h>
3233
#include "smsc95xx.h"
3334

3435
#define SMSC_CHIPNAME "smsc95xx"
@@ -765,6 +766,15 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
765766

766767
static void smsc95xx_init_mac_address(struct usbnet *dev)
767768
{
769+
const u8 *mac_addr;
770+
771+
/* maybe the boot loader passed the MAC address in devicetree */
772+
mac_addr = of_get_mac_address(dev->udev->dev.of_node);
773+
if (mac_addr) {
774+
memcpy(dev->net->dev_addr, mac_addr, ETH_ALEN);
775+
return;
776+
}
777+
768778
/* try reading mac address from EEPROM */
769779
if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
770780
dev->net->dev_addr) == 0) {
@@ -775,7 +785,7 @@ static void smsc95xx_init_mac_address(struct usbnet *dev)
775785
}
776786
}
777787

778-
/* no eeprom, or eeprom values are invalid. generate random MAC */
788+
/* no useful static MAC address found. generate a random one */
779789
eth_hw_addr_random(dev->net);
780790
netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
781791
}

0 commit comments

Comments
 (0)