40 lines
1.3 KiB
Diff
40 lines
1.3 KiB
Diff
From 27dfe6f4347e883fd618d5a37500c7f6d3652fb9 Mon Sep 17 00:00:00 2001
|
|
From: hmz007 <hmz007@gmail.com>
|
|
Date: Fri, 22 Nov 2019 19:03:00 +0800
|
|
Subject: [PATCH] r8152: support to get MAC address from device tree
|
|
|
|
Signed-off-by: hmz007 <hmz007@gmail.com>
|
|
---
|
|
drivers/net/usb/r8152.c | 12 ++++++++++++
|
|
1 file changed, 12 insertions(+)
|
|
|
|
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
|
|
index b2507c59ba8b..eb78f6d9390c 100644
|
|
--- a/drivers/net/usb/r8152.c
|
|
+++ b/drivers/net/usb/r8152.c
|
|
@@ -6,6 +6,7 @@
|
|
#include <linux/signal.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/module.h>
|
|
+#include <linux/of_net.h>
|
|
#include <linux/netdevice.h>
|
|
#include <linux/etherdevice.h>
|
|
#include <linux/mii.h>
|
|
@@ -1298,6 +1299,17 @@ static int determine_ethernet_addr(struct r8152 *tp, struct sockaddr *sa)
|
|
if (ret < 0) {
|
|
netif_err(tp, probe, dev, "Get ether addr fail\n");
|
|
} else if (!is_valid_ether_addr(sa->sa_data)) {
|
|
+ /* try to get MAC address from DT */
|
|
+ if (tp->udev->dev.of_node) {
|
|
+ const u8 *mac = of_get_mac_address(tp->udev->dev.of_node);
|
|
+ if (!IS_ERR(mac) && is_valid_ether_addr(mac)) {
|
|
+ ether_addr_copy(sa->sa_data, mac);
|
|
+ netif_info(tp, probe, dev, "DT mac addr %pM\n",
|
|
+ sa->sa_data);
|
|
+ return 0;
|
|
+ }
|
|
+ }
|
|
+
|
|
netif_err(tp, probe, dev, "Invalid ether addr %pM\n",
|
|
sa->sa_data);
|
|
eth_hw_addr_random(dev);
|