diff options
author | Arnd Bergmann <arnd@arndb.de> | 2016-04-29 03:05:59 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-05-01 20:57:45 -0400 |
commit | c489565b536ff5382460273fd9513f0adebec024 (patch) | |
tree | cb3cd2927de267f3cc8407e9f78962f18b5574fe /drivers/net/usb | |
parent | 90e5d0db2b221f0cbbb91e9e61fdb7dbb9e1afc2 (diff) |
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>
Diffstat (limited to 'drivers/net/usb')
-rw-r--r-- | drivers/net/usb/smsc75xx.c | 12 | ||||
-rw-r--r-- | drivers/net/usb/smsc95xx.c | 12 |
2 files changed, 22 insertions, 2 deletions
diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c index 30033dbe6662..c369db99c005 100644 --- a/drivers/net/usb/smsc75xx.c +++ b/drivers/net/usb/smsc75xx.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/crc32.h> | 29 | #include <linux/crc32.h> |
30 | #include <linux/usb/usbnet.h> | 30 | #include <linux/usb/usbnet.h> |
31 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
32 | #include <linux/of_net.h> | ||
32 | #include "smsc75xx.h" | 33 | #include "smsc75xx.h" |
33 | 34 | ||
34 | #define SMSC_CHIPNAME "smsc75xx" | 35 | #define SMSC_CHIPNAME "smsc75xx" |
@@ -761,6 +762,15 @@ static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) | |||
761 | 762 | ||
762 | static void smsc75xx_init_mac_address(struct usbnet *dev) | 763 | static void smsc75xx_init_mac_address(struct usbnet *dev) |
763 | { | 764 | { |
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 | |||
764 | /* try reading mac address from EEPROM */ | 774 | /* try reading mac address from EEPROM */ |
765 | if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, | 775 | if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, |
766 | dev->net->dev_addr) == 0) { | 776 | dev->net->dev_addr) == 0) { |
@@ -772,7 +782,7 @@ static void smsc75xx_init_mac_address(struct usbnet *dev) | |||
772 | } | 782 | } |
773 | } | 783 | } |
774 | 784 | ||
775 | /* no eeprom, or eeprom values are invalid. generate random MAC */ | 785 | /* no useful static MAC address found. generate a random one */ |
776 | eth_hw_addr_random(dev->net); | 786 | eth_hw_addr_random(dev->net); |
777 | netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); | 787 | netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); |
778 | } | 788 | } |
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index 66b3ab9f614e..2edc2bc6d1b9 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/crc32.h> | 29 | #include <linux/crc32.h> |
30 | #include <linux/usb/usbnet.h> | 30 | #include <linux/usb/usbnet.h> |
31 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
32 | #include <linux/of_net.h> | ||
32 | #include "smsc95xx.h" | 33 | #include "smsc95xx.h" |
33 | 34 | ||
34 | #define SMSC_CHIPNAME "smsc95xx" | 35 | #define SMSC_CHIPNAME "smsc95xx" |
@@ -765,6 +766,15 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) | |||
765 | 766 | ||
766 | static void smsc95xx_init_mac_address(struct usbnet *dev) | 767 | static void smsc95xx_init_mac_address(struct usbnet *dev) |
767 | { | 768 | { |
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 | |||
768 | /* try reading mac address from EEPROM */ | 778 | /* try reading mac address from EEPROM */ |
769 | if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, | 779 | if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, |
770 | dev->net->dev_addr) == 0) { | 780 | dev->net->dev_addr) == 0) { |
@@ -775,7 +785,7 @@ static void smsc95xx_init_mac_address(struct usbnet *dev) | |||
775 | } | 785 | } |
776 | } | 786 | } |
777 | 787 | ||
778 | /* no eeprom, or eeprom values are invalid. generate random MAC */ | 788 | /* no useful static MAC address found. generate a random one */ |
779 | eth_hw_addr_random(dev->net); | 789 | eth_hw_addr_random(dev->net); |
780 | netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); | 790 | netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); |
781 | } | 791 | } |