Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1326455 > unrolled thread

[PATCH 2/2] net/smscx5xx: use the device tree for mac address

Started byLubomir Rintel <lkundrak@v3.sk>
First post2016-02-04 08:40 +0100
Last post2016-02-04 09:30 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 2/2] net/smscx5xx: use the device tree for mac address Lubomir Rintel <lkundrak@v3.sk> - 2016-02-04 08:40 +0100
    Re: [PATCH 2/2] net/smscx5xx: use the device tree for mac address Arnd Bergmann <arnd@arndb.de> - 2016-02-04 09:30 +0100

#1326455 — [PATCH 2/2] net/smscx5xx: use the device tree for mac address

FromLubomir Rintel <lkundrak@v3.sk>
Date2016-02-04 08:40 +0100
Subject[PATCH 2/2] net/smscx5xx: use the device tree for mac address
Message-ID<qYmGe-5vX-19@gated-at.bofh.it>
From: Arnd Bergmann <arnd@arndb.de>

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>
---
Changes since v1:
  - Made use of_get_property()
  - Amended comments/commit message a bit

 drivers/net/usb/smsc75xx.c | 12 +++++++++++-
 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 30033db..8266e27 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -29,6 +29,7 @@
 #include <linux/crc32.h>
 #include <linux/usb/usbnet.h>
 #include <linux/slab.h>
+#include <linux/of_net.h>
 #include "smsc75xx.h"
 
 #define SMSC_CHIPNAME			"smsc75xx"
@@ -761,6 +762,8 @@ static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
 
 static void smsc75xx_init_mac_address(struct usbnet *dev)
 {
+	const u8 *mac_addr;
+
 	/* try reading mac address from EEPROM */
 	if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
 			dev->net->dev_addr) == 0) {
@@ -772,7 +775,14 @@ static void smsc75xx_init_mac_address(struct usbnet *dev)
 		}
 	}
 
-	/* no eeprom, or eeprom values are invalid. generate random MAC */
+	/* maybe the boot loader passed the MAC address in devicetree */
+	mac_addr = of_get_mac_address (dev->udev->dev.of_node);
+	if (mac_addr) {
+		memcpy(dev->net->dev_addr, mac_addr, ETH_ALEN);
+		return;
+	}
+
+	/* no useful static MAC address found. generate a random one */
 	eth_hw_addr_random(dev->net);
 	netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
 }
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 66b3ab9..623bb2e 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -29,6 +29,7 @@
 #include <linux/crc32.h>
 #include <linux/usb/usbnet.h>
 #include <linux/slab.h>
+#include <linux/of_net.h>
 #include "smsc95xx.h"
 
 #define SMSC_CHIPNAME			"smsc95xx"
@@ -765,6 +766,8 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
 
 static void smsc95xx_init_mac_address(struct usbnet *dev)
 {
+	const u8 *mac_addr;
+
 	/* try reading mac address from EEPROM */
 	if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
 			dev->net->dev_addr) == 0) {
@@ -775,7 +778,14 @@ static void smsc95xx_init_mac_address(struct usbnet *dev)
 		}
 	}
 
-	/* no eeprom, or eeprom values are invalid. generate random MAC */
+	/* maybe the boot loader passed the MAC address in devicetree */
+	mac_addr = of_get_mac_address (dev->udev->dev.of_node);
+	if (mac_addr) {
+		memcpy(dev->net->dev_addr, mac_addr, ETH_ALEN);
+		return;
+	}
+
+	/* no useful static MAC address found. generate a random one */
 	eth_hw_addr_random(dev->net);
 	netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
 }
-- 
2.5.0

[toc] | [next] | [standalone]


#1326475

FromArnd Bergmann <arnd@arndb.de>
Date2016-02-04 09:30 +0100
Message-ID<qYnsB-65V-9@gated-at.bofh.it>
In reply to#1326455
On Thursday 04 February 2016 08:36:04 Lubomir Rintel wrote:
> 
> [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>
> ---
> 

Looks good to me now. We could debate which MAC address should
be used when both EEPROM and DT exist. The current version prefers
the EEPROM address, and I think some other drivers do the opposite,
but I don't really know which is best.

	Arnd

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web