treewide: backport support for nvmem on non platform devices

In the current state, nvmem cells are only detected on platform device.
To quickly fix the problem, we register the affected problematic driver
with the of_platform but that is more an hack than a real solution.
Backport from net-next the required patch so that nvmem can work also
with non-platform devices and rework our current patch.
Drop the mediatek and dsa workaround and rework the ath10k patches.
Rework every driver that use the of_get_mac_address api.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
This commit is contained in:
Ansuel Smith 2021-07-23 20:19:43 +02:00 committed by David Bauer
parent edb6bc1990
commit 91a52f22a1
35 changed files with 4460 additions and 500 deletions

View File

@ -20,38 +20,19 @@ diff --git a/ath10k-5.10/core.c b/ath10k-5.10/core.c
index 5f4e12196..9ed7b9883 100644
--- a/ath10k-5.10/core.c
+++ b/ath10k-5.10/core.c
@@ -8,6 +8,9 @@
@@ -8,6 +8,7 @@
#include <linux/module.h>
#include <linux/firmware.h>
#include <linux/of.h>
+#include <linux/of_net.h>
+#include <linux/of_platform.h>
+#include <linux/property.h>
#include <linux/property.h>
#include <linux/dmi.h>
#include <linux/ctype.h>
@@ -2961,8 +2963,14 @@ EXPORT_SYMBOL(ath10k_core_stop);
static int ath10k_core_probe_fw(struct ath10k *ar)
{
struct bmi_target_info target_info;
+ const char *mac;
int ret = 0;
+#ifdef CONFIG_OF
+ /* register the platform to be found by the of api */
+ of_platform_device_create(ar->dev->of_node, NULL, NULL);
+#endif
+
ret = ath10k_hif_power_up(ar, ATH10K_FIRMWARE_MODE_NORMAL);
if (ret) {
ath10k_err(ar, "could not power on hif bus (%d)\n", ret);
@@ -3062,6 +3068,10 @@ static int ath10k_core_probe_fw(struct ath10k *ar)
@@ -3062,6 +3068,8 @@ static int ath10k_core_probe_fw(struct ath10k *ar)
device_get_mac_address(ar->dev, ar->mac_addr, sizeof(ar->mac_addr));
+ mac = of_get_mac_address(ar->dev->of_node);
+ if (!IS_ERR(mac))
+ ether_addr_copy(ar->mac_addr, mac);
+ of_get_mac_address(ar->dev->of_node, ar->mac_addr);
+
ret = ath10k_core_init_firmware_features(ar);
if (ret) {

View File

@ -20,38 +20,19 @@ diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/a
index 5f4e12196..9ed7b9883 100644
--- a/drivers/net/wireless/ath/ath10k/core.c
+++ b/drivers/net/wireless/ath/ath10k/core.c
@@ -8,6 +8,9 @@
@@ -8,6 +8,7 @@
#include <linux/module.h>
#include <linux/firmware.h>
#include <linux/of.h>
+#include <linux/of_net.h>
+#include <linux/of_platform.h>
+#include <linux/property.h>
#include <linux/property.h>
#include <linux/dmi.h>
#include <linux/ctype.h>
@@ -2961,8 +2963,14 @@ EXPORT_SYMBOL(ath10k_core_stop);
static int ath10k_core_probe_fw(struct ath10k *ar)
{
struct bmi_target_info target_info;
+ const char *mac;
int ret = 0;
+#ifdef CONFIG_OF
+ /* register the platform to be found by the of api */
+ of_platform_device_create(ar->dev->of_node, NULL, NULL);
+#endif
+
ret = ath10k_hif_power_up(ar, ATH10K_FIRMWARE_MODE_NORMAL);
if (ret) {
ath10k_err(ar, "could not power on hif bus (%d)\n", ret);
@@ -3062,6 +3068,10 @@ static int ath10k_core_probe_fw(struct ath10k *ar)
@@ -3062,6 +3068,8 @@ static int ath10k_core_probe_fw(struct ath10k *ar)
device_get_mac_address(ar->dev, ar->mac_addr, sizeof(ar->mac_addr));
+ mac = of_get_mac_address(ar->dev->of_node);
+ if (!IS_ERR(mac))
+ ether_addr_copy(ar->mac_addr, mac);
+ of_get_mac_address(ar->dev->of_node, ar->mac_addr);
+
ret = ath10k_core_init_firmware_features(ar);
if (ret) {

View File

@ -1,19 +1,18 @@
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
@@ -990,8 +990,13 @@ static void rt2x00lib_rate(struct ieee80
@@ -990,6 +990,12 @@ static void rt2x00lib_rate(struct ieee80
void rt2x00lib_set_mac_address(struct rt2x00_dev *rt2x00dev, u8 *eeprom_mac_addr)
{
+ struct rt2x00_platform_data *pdata;
const char *mac_addr;
+
+ pdata = rt2x00dev->dev->platform_data;
+ if (pdata && pdata->mac_address)
+ ether_addr_copy(eeprom_mac_addr, pdata->mac_address);
+
mac_addr = of_get_mac_address(rt2x00dev->dev->of_node);
if (!IS_ERR(mac_addr))
ether_addr_copy(eeprom_mac_addr, mac_addr);
of_get_mac_address(rt2x00dev->dev->of_node, eeprom_mac_addr);
if (!is_valid_ether_addr(eeprom_mac_addr)) {
--- a/include/linux/rt2x00_platform.h
+++ b/include/linux/rt2x00_platform.h
@@ -14,6 +14,7 @@

View File

@ -0,0 +1,245 @@
From 83216e3988cd196183542937c9bd58b279f946af Mon Sep 17 00:00:00 2001
From: Michael Walle <michael@walle.cc>
Date: Mon, 12 Apr 2021 19:47:17 +0200
Subject: of: net: pass the dst buffer to of_get_mac_address()
of_get_mac_address() returns a "const void*" pointer to a MAC address.
Lately, support to fetch the MAC address by an NVMEM provider was added.
But this will only work with platform devices. It will not work with
PCI devices (e.g. of an integrated root complex) and esp. not with DSA
ports.
There is an of_* variant of the nvmem binding which works without
devices. The returned data of a nvmem_cell_read() has to be freed after
use. On the other hand the return of_get_mac_address() points to some
static data without a lifetime. The trick for now, was to allocate a
device resource managed buffer which is then returned. This will only
work if we have an actual device.
Change it, so that the caller of of_get_mac_address() has to supply a
buffer where the MAC address is written to. Unfortunately, this will
touch all drivers which use the of_get_mac_address().
Usually the code looks like:
const char *addr;
addr = of_get_mac_address(np);
if (!IS_ERR(addr))
ether_addr_copy(ndev->dev_addr, addr);
This can then be simply rewritten as:
of_get_mac_address(np, ndev->dev_addr);
Sometimes is_valid_ether_addr() is used to test the MAC address.
of_get_mac_address() already makes sure, it just returns a valid MAC
address. Thus we can just test its return code. But we have to be
careful if there are still other sources for the MAC address before the
of_get_mac_address(). In this case we have to keep the
is_valid_ether_addr() call.
The following coccinelle patch was used to convert common cases to the
new style. Afterwards, I've manually gone over the drivers and fixed the
return code variable: either used a new one or if one was already
available use that. Mansour Moufid, thanks for that coccinelle patch!
<spml>
@a@
identifier x;
expression y, z;
@@
- x = of_get_mac_address(y);
+ x = of_get_mac_address(y, z);
<...
- ether_addr_copy(z, x);
...>
@@
identifier a.x;
@@
- if (<+... x ...+>) {}
@@
identifier a.x;
@@
if (<+... x ...+>) {
...
}
- else {}
@@
identifier a.x;
expression e;
@@
- if (<+... x ...+>@e)
- {}
- else
+ if (!(e))
{...}
@@
expression x, y, z;
@@
- x = of_get_mac_address(y, z);
+ of_get_mac_address(y, z);
... when != x
</spml>
All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
compile-time tested.
Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
---
arch/arm/mach-mvebu/kirkwood.c | 3 +-
arch/powerpc/sysdev/tsi108_dev.c | 5 +-
drivers/net/ethernet/aeroflex/greth.c | 6 +--
drivers/net/ethernet/allwinner/sun4i-emac.c | 10 ++--
drivers/net/ethernet/altera/altera_tse_main.c | 7 +--
drivers/net/ethernet/arc/emac_main.c | 8 +--
drivers/net/ethernet/atheros/ag71xx.c | 7 +--
drivers/net/ethernet/broadcom/bcm4908_enet.c | 7 +--
drivers/net/ethernet/broadcom/bcmsysport.c | 7 +--
drivers/net/ethernet/broadcom/bgmac-bcma.c | 10 ++--
drivers/net/ethernet/broadcom/bgmac-platform.c | 11 ++--
drivers/net/ethernet/cadence/macb_main.c | 11 ++--
drivers/net/ethernet/cavium/octeon/octeon_mgmt.c | 8 +--
drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 5 +-
drivers/net/ethernet/davicom/dm9000.c | 10 ++--
drivers/net/ethernet/ethoc.c | 6 +--
drivers/net/ethernet/ezchip/nps_enet.c | 7 +--
drivers/net/ethernet/freescale/fec_main.c | 7 +--
drivers/net/ethernet/freescale/fec_mpc52xx.c | 7 +--
drivers/net/ethernet/freescale/fman/mac.c | 9 ++--
.../net/ethernet/freescale/fs_enet/fs_enet-main.c | 5 +-
drivers/net/ethernet/freescale/gianfar.c | 8 +--
drivers/net/ethernet/freescale/ucc_geth.c | 5 +-
drivers/net/ethernet/hisilicon/hisi_femac.c | 7 +--
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 7 +--
drivers/net/ethernet/lantiq_xrx200.c | 7 +--
drivers/net/ethernet/marvell/mv643xx_eth.c | 5 +-
drivers/net/ethernet/marvell/mvneta.c | 6 +--
.../net/ethernet/marvell/prestera/prestera_main.c | 11 ++--
drivers/net/ethernet/marvell/pxa168_eth.c | 9 +---
drivers/net/ethernet/marvell/sky2.c | 8 ++-
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 11 ++--
drivers/net/ethernet/micrel/ks8851_common.c | 7 ++-
drivers/net/ethernet/microchip/lan743x_main.c | 5 +-
drivers/net/ethernet/nxp/lpc_eth.c | 4 +-
drivers/net/ethernet/qualcomm/qca_spi.c | 10 ++--
drivers/net/ethernet/qualcomm/qca_uart.c | 9 +---
drivers/net/ethernet/renesas/ravb_main.c | 12 +++--
drivers/net/ethernet/renesas/sh_eth.c | 5 +-
.../net/ethernet/samsung/sxgbe/sxgbe_platform.c | 13 ++---
drivers/net/ethernet/socionext/sni_ave.c | 10 ++--
.../net/ethernet/stmicro/stmmac/dwmac-anarion.c | 2 +-
.../ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-generic.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-intel-plat.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-ipq806x.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-mediatek.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-meson8b.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c | 2 +-
.../ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-visconti.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 +-
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
.../net/ethernet/stmicro/stmmac/stmmac_platform.c | 14 ++---
.../net/ethernet/stmicro/stmmac/stmmac_platform.h | 2 +-
drivers/net/ethernet/ti/am65-cpsw-nuss.c | 19 ++++---
drivers/net/ethernet/ti/cpsw.c | 7 +--
drivers/net/ethernet/ti/cpsw_new.c | 7 +--
drivers/net/ethernet/ti/davinci_emac.c | 8 +--
drivers/net/ethernet/ti/netcp_core.c | 7 +--
drivers/net/ethernet/wiznet/w5100-spi.c | 8 ++-
drivers/net/ethernet/wiznet/w5100.c | 2 +-
drivers/net/ethernet/xilinx/ll_temac_main.c | 8 +--
drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 15 +++---
drivers/net/ethernet/xilinx/xilinx_emaclite.c | 8 +--
drivers/net/wireless/ath/ath9k/init.c | 5 +-
drivers/net/wireless/mediatek/mt76/eeprom.c | 9 +---
drivers/net/wireless/ralink/rt2x00/rt2x00dev.c | 6 +--
drivers/of/of_net.c | 60 ++++++++++------------
drivers/staging/octeon/ethernet.c | 10 ++--
drivers/staging/wfx/main.c | 7 ++-
include/linux/of_net.h | 6 +--
include/net/dsa.h | 2 +-
net/dsa/dsa2.c | 2 +-
net/dsa/slave.c | 2 +-
net/ethernet/eth.c | 11 ++--
85 files changed, 218 insertions(+), 364 deletions(-)
diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index 01f9c26f9bf37..e9a36dd7144f1 100644
--- a/drivers/net/wireless/ath/ath9k/init.c
+++ b/drivers/net/wireless/ath/ath9k/init.c
@@ -617,7 +617,6 @@ static int ath9k_of_init(struct ath_softc *sc)
struct ath_hw *ah = sc->sc_ah;
struct ath_common *common = ath9k_hw_common(ah);
enum ath_bus_type bus_type = common->bus_ops->ath_bus_type;
- const char *mac;
char eeprom_name[100];
int ret;
@@ -640,9 +639,7 @@ static int ath9k_of_init(struct ath_softc *sc)
ah->ah_flags |= AH_NO_EEP_SWAP;
}
- mac = of_get_mac_address(np);
- if (!IS_ERR(mac))
- ether_addr_copy(common->macaddr, mac);
+ of_get_mac_address(np, common->macaddr);
return 0;
}
diff --git a/drivers/net/wireless/mediatek/mt76/eeprom.c b/drivers/net/wireless/mediatek/mt76/eeprom.c
index 665b54c5c8ae5..6d895738222ad 100644
--- a/drivers/net/wireless/mediatek/mt76/eeprom.c
+++ b/drivers/net/wireless/mediatek/mt76/eeprom.c
@@ -91,15 +91,9 @@ void
void
mt76_eeprom_override(struct mt76_dev *dev)
{
-#ifdef CONFIG_OF
struct device_node *np = dev->dev->of_node;
- const u8 *mac = NULL;
- if (np)
- mac = of_get_mac_address(np);
- if (!IS_ERR_OR_NULL(mac))
- ether_addr_copy(dev->macaddr, mac);
-#endif
+ of_get_mac_address(np, dev->macaddr);
if (!is_valid_ether_addr(dev->macaddr)) {
eth_random_addr(dev->macaddr);
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
index 61a4f1ad31e28..e95c101c27111 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
@@ -989,11 +989,7 @@ static void rt2x00lib_rate(struct ieee80211_rate *entry,
void rt2x00lib_set_mac_address(struct rt2x00_dev *rt2x00dev, u8 *eeprom_mac_addr)
{
- const char *mac_addr;
-
- mac_addr = of_get_mac_address(rt2x00dev->dev->of_node);
- if (!IS_ERR(mac_addr))
- ether_addr_copy(eeprom_mac_addr, mac_addr);
+ of_get_mac_address(rt2x00dev->dev->of_node, eeprom_mac_addr);
if (!is_valid_ether_addr(eeprom_mac_addr)) {
eth_random_addr(eeprom_mac_addr);
--
cgit 1.2.3-1.el7

View File

@ -0,0 +1,206 @@
From 83216e3988cd196183542937c9bd58b279f946af Mon Sep 17 00:00:00 2001
From: Michael Walle <michael@walle.cc>
Date: Mon, 12 Apr 2021 19:47:17 +0200
Subject: of: net: pass the dst buffer to of_get_mac_address()
of_get_mac_address() returns a "const void*" pointer to a MAC address.
Lately, support to fetch the MAC address by an NVMEM provider was added.
But this will only work with platform devices. It will not work with
PCI devices (e.g. of an integrated root complex) and esp. not with DSA
ports.
There is an of_* variant of the nvmem binding which works without
devices. The returned data of a nvmem_cell_read() has to be freed after
use. On the other hand the return of_get_mac_address() points to some
static data without a lifetime. The trick for now, was to allocate a
device resource managed buffer which is then returned. This will only
work if we have an actual device.
Change it, so that the caller of of_get_mac_address() has to supply a
buffer where the MAC address is written to. Unfortunately, this will
touch all drivers which use the of_get_mac_address().
Usually the code looks like:
const char *addr;
addr = of_get_mac_address(np);
if (!IS_ERR(addr))
ether_addr_copy(ndev->dev_addr, addr);
This can then be simply rewritten as:
of_get_mac_address(np, ndev->dev_addr);
Sometimes is_valid_ether_addr() is used to test the MAC address.
of_get_mac_address() already makes sure, it just returns a valid MAC
address. Thus we can just test its return code. But we have to be
careful if there are still other sources for the MAC address before the
of_get_mac_address(). In this case we have to keep the
is_valid_ether_addr() call.
The following coccinelle patch was used to convert common cases to the
new style. Afterwards, I've manually gone over the drivers and fixed the
return code variable: either used a new one or if one was already
available use that. Mansour Moufid, thanks for that coccinelle patch!
<spml>
@a@
identifier x;
expression y, z;
@@
- x = of_get_mac_address(y);
+ x = of_get_mac_address(y, z);
<...
- ether_addr_copy(z, x);
...>
@@
identifier a.x;
@@
- if (<+... x ...+>) {}
@@
identifier a.x;
@@
if (<+... x ...+>) {
...
}
- else {}
@@
identifier a.x;
expression e;
@@
- if (<+... x ...+>@e)
- {}
- else
+ if (!(e))
{...}
@@
expression x, y, z;
@@
- x = of_get_mac_address(y, z);
+ of_get_mac_address(y, z);
... when != x
</spml>
All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
compile-time tested.
Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
---
arch/arm/mach-mvebu/kirkwood.c | 3 +-
arch/powerpc/sysdev/tsi108_dev.c | 5 +-
drivers/net/ethernet/aeroflex/greth.c | 6 +--
drivers/net/ethernet/allwinner/sun4i-emac.c | 10 ++--
drivers/net/ethernet/altera/altera_tse_main.c | 7 +--
drivers/net/ethernet/arc/emac_main.c | 8 +--
drivers/net/ethernet/atheros/ag71xx.c | 7 +--
drivers/net/ethernet/broadcom/bcm4908_enet.c | 7 +--
drivers/net/ethernet/broadcom/bcmsysport.c | 7 +--
drivers/net/ethernet/broadcom/bgmac-bcma.c | 10 ++--
drivers/net/ethernet/broadcom/bgmac-platform.c | 11 ++--
drivers/net/ethernet/cadence/macb_main.c | 11 ++--
drivers/net/ethernet/cavium/octeon/octeon_mgmt.c | 8 +--
drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 5 +-
drivers/net/ethernet/davicom/dm9000.c | 10 ++--
drivers/net/ethernet/ethoc.c | 6 +--
drivers/net/ethernet/ezchip/nps_enet.c | 7 +--
drivers/net/ethernet/freescale/fec_main.c | 7 +--
drivers/net/ethernet/freescale/fec_mpc52xx.c | 7 +--
drivers/net/ethernet/freescale/fman/mac.c | 9 ++--
.../net/ethernet/freescale/fs_enet/fs_enet-main.c | 5 +-
drivers/net/ethernet/freescale/gianfar.c | 8 +--
drivers/net/ethernet/freescale/ucc_geth.c | 5 +-
drivers/net/ethernet/hisilicon/hisi_femac.c | 7 +--
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 7 +--
drivers/net/ethernet/lantiq_xrx200.c | 7 +--
drivers/net/ethernet/marvell/mv643xx_eth.c | 5 +-
drivers/net/ethernet/marvell/mvneta.c | 6 +--
.../net/ethernet/marvell/prestera/prestera_main.c | 11 ++--
drivers/net/ethernet/marvell/pxa168_eth.c | 9 +---
drivers/net/ethernet/marvell/sky2.c | 8 ++-
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 11 ++--
drivers/net/ethernet/micrel/ks8851_common.c | 7 ++-
drivers/net/ethernet/microchip/lan743x_main.c | 5 +-
drivers/net/ethernet/nxp/lpc_eth.c | 4 +-
drivers/net/ethernet/qualcomm/qca_spi.c | 10 ++--
drivers/net/ethernet/qualcomm/qca_uart.c | 9 +---
drivers/net/ethernet/renesas/ravb_main.c | 12 +++--
drivers/net/ethernet/renesas/sh_eth.c | 5 +-
.../net/ethernet/samsung/sxgbe/sxgbe_platform.c | 13 ++---
drivers/net/ethernet/socionext/sni_ave.c | 10 ++--
.../net/ethernet/stmicro/stmmac/dwmac-anarion.c | 2 +-
.../ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-generic.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-intel-plat.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-ipq806x.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-mediatek.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-meson8b.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c | 2 +-
.../ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c | 2 +-
.../net/ethernet/stmicro/stmmac/dwmac-visconti.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 +-
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
.../net/ethernet/stmicro/stmmac/stmmac_platform.c | 14 ++---
.../net/ethernet/stmicro/stmmac/stmmac_platform.h | 2 +-
drivers/net/ethernet/ti/am65-cpsw-nuss.c | 19 ++++---
drivers/net/ethernet/ti/cpsw.c | 7 +--
drivers/net/ethernet/ti/cpsw_new.c | 7 +--
drivers/net/ethernet/ti/davinci_emac.c | 8 +--
drivers/net/ethernet/ti/netcp_core.c | 7 +--
drivers/net/ethernet/wiznet/w5100-spi.c | 8 ++-
drivers/net/ethernet/wiznet/w5100.c | 2 +-
drivers/net/ethernet/xilinx/ll_temac_main.c | 8 +--
drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 15 +++---
drivers/net/ethernet/xilinx/xilinx_emaclite.c | 8 +--
drivers/net/wireless/ath/ath9k/init.c | 5 +-
drivers/net/wireless/mediatek/mt76/eeprom.c | 9 +---
drivers/net/wireless/ralink/rt2x00/rt2x00dev.c | 6 +--
drivers/of/of_net.c | 60 ++++++++++------------
drivers/staging/octeon/ethernet.c | 10 ++--
drivers/staging/wfx/main.c | 7 ++-
include/linux/of_net.h | 6 +--
include/net/dsa.h | 2 +-
net/dsa/dsa2.c | 2 +-
net/dsa/slave.c | 2 +-
net/ethernet/eth.c | 11 ++--
85 files changed, 218 insertions(+), 364 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/eeprom.c b/drivers/net/wireless/mediatek/mt76/eeprom.c
index 665b54c5c8ae5..6d895738222ad 100644
--- a/eeprom.c
+++ b/eeprom.c
@@ -91,15 +91,9 @@ void
{
struct mt76_dev *dev = phy->dev;
-#ifdef CONFIG_OF
struct device_node *np = dev->dev->of_node;
- const u8 *mac = NULL;
- if (np)
- mac = of_get_mac_address(np);
- if (!IS_ERR_OR_NULL(mac))
- ether_addr_copy(phy->macaddr, mac);
-#endif
+ of_get_mac_address(np, phy->macaddr);
if (!is_valid_ether_addr(phy->macaddr)) {
eth_random_addr(phy->macaddr);
--
cgit 1.2.3-1.el7

View File

@ -1519,7 +1519,6 @@ static int ag71xx_probe(struct platform_device *pdev)
struct net_device *dev;
struct resource *res;
struct ag71xx *ag;
const void *mac_addr;
u32 max_frame_len;
int tx_size, err;
@ -1668,12 +1667,10 @@ static int ag71xx_probe(struct platform_device *pdev)
ag->stop_desc->ctrl = 0;
ag->stop_desc->next = (u32) ag->stop_desc_dma;
mac_addr = of_get_mac_address(np);
if (IS_ERR_OR_NULL(mac_addr) || !is_valid_ether_addr(mac_addr)) {
of_get_mac_address(np, dev->dev_addr);
if (!is_valid_ether_addr(dev->dev_addr)) {
dev_err(&pdev->dev, "invalid MAC address, using random address\n");
eth_random_addr(dev->dev_addr);
} else {
memcpy(dev->dev_addr, mac_addr, ETH_ALEN);
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,10,0)

View File

@ -25,23 +25,13 @@ Signed-off-by: David S. Miller <davem@davemloft.net>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/string.h>
@@ -620,6 +621,7 @@ static int bcm4908_enet_probe(struct pla
struct device *dev = &pdev->dev;
struct net_device *netdev;
struct bcm4908_enet *enet;
+ const u8 *mac;
int err;
netdev = devm_alloc_etherdev(dev, sizeof(*enet));
@@ -647,7 +649,11 @@ static int bcm4908_enet_probe(struct pla
@@ -647,7 +649,9 @@ static int bcm4908_enet_probe(struct pla
return err;
SET_NETDEV_DEV(netdev, &pdev->dev);
- eth_hw_addr_random(netdev);
+ mac = of_get_mac_address(dev->of_node);
+ if (!IS_ERR(mac))
+ ether_addr_copy(netdev->dev_addr, mac);
+ else
+ of_get_mac_address(dev->of_node, netdev->dev_addr);
+ if (!is_valid_ether_addr(netdev->dev_addr))
+ eth_hw_addr_random(netdev);
netdev->netdev_ops = &bcm4908_enet_netdev_ops;
netdev->min_mtu = ETH_ZLEN;

View File

@ -167,7 +167,6 @@ static int ath9k_fixup_probe(struct platform_device *pdev)
struct device_node *node = dev->of_node;
struct ath9k_fixup *priv;
struct resource *res;
const void *mac;
int ret;
if (ath9k_num_fixups >= ATH9K_MAX_FIXUPS)
@ -200,9 +199,8 @@ static int ath9k_fixup_probe(struct platform_device *pdev)
priv->pdata.led_active_high = of_property_read_bool(node,
"ath,led-active-high");
mac = of_get_mac_address(node);
if (!IS_ERR_OR_NULL(mac)) {
memcpy(priv->mac, mac, ETH_ALEN);
of_get_mac_address(node, priv->mac);
if (is_valid_ether_addr(priv->mac)) {
dev_info(dev, "mtd mac %pM\n", priv->mac);
} else {
random_ether_addr(priv->mac);

View File

@ -1119,7 +1119,6 @@ static int b43_sprom_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct device_node *node = dev->of_node;
struct b43_sprom *priv = &b43_sprom;
const void *mac;
int ret;
priv->dev = dev;
@ -1129,9 +1128,8 @@ static int b43_sprom_probe(struct platform_device *pdev)
of_property_read_u32(node, "pci-bus", &priv->pci_bus);
of_property_read_u32(node, "pci-dev", &priv->pci_dev);
mac = of_get_mac_address(node);
if (!IS_ERR_OR_NULL(mac)) {
memcpy(priv->mac, mac, ETH_ALEN);
of_get_mac_address(node, priv->mac);
if (is_valid_ether_addr(priv->mac)) {
dev_info(dev, "mtd mac %pM\n", priv->mac);
} else {
random_ether_addr(priv->mac);

View File

@ -864,7 +864,6 @@ static int bcm6368_enetsw_probe(struct platform_device *pdev)
struct device_node *node = dev->of_node;
struct net_device *ndev;
struct resource *res;
const void *mac;
unsigned i;
int ret;
@ -953,9 +952,8 @@ static int bcm6368_enetsw_probe(struct platform_device *pdev)
priv->dma_chan_int_mask = DMAC_IR_PKTDONE_MASK;
priv->dma_chan_width = DMA_CHAN_WIDTH;
mac = of_get_mac_address(node);
if (!IS_ERR_OR_NULL(mac)) {
memcpy(ndev->dev_addr, mac, ETH_ALEN);
of_get_mac_address(node, ndev->dev_addr);
if (is_valid_ether_addr(ndev->dev_addr)) {
dev_info(dev, "mtd mac %pM\n", ndev->dev_addr);
} else {
random_ether_addr(ndev->dev_addr);

View File

@ -0,0 +1,77 @@
From f10843e04a075202dbb39dfcee047e3a2fdf5a8d Mon Sep 17 00:00:00 2001
From: Michael Walle <michael@walle.cc>
Date: Mon, 12 Apr 2021 19:47:18 +0200
Subject: of: net: fix of_get_mac_addr_nvmem() for non-platform devices
of_get_mac_address() already supports fetching the MAC address by an
nvmem provider. But until now, it was just working for platform devices.
Esp. it was not working for DSA ports and PCI devices. It gets more
common that PCI devices have a device tree binding since SoCs contain
integrated root complexes.
Use the nvmem of_* binding to fetch the nvmem cells by a struct
device_node. We still have to try to read the cell by device first
because there might be a nvmem_cell_lookup associated with that device.
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
---
drivers/of/of_net.c | 35 ++++++++++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 5 deletions(-)
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -11,6 +11,7 @@
#include <linux/phy.h>
#include <linux/export.h>
#include <linux/device.h>
+#include <linux/nvmem-consumer.h>
/**
* of_get_phy_mode - Get phy mode for given device_node
@@ -59,15 +60,39 @@ static int of_get_mac_addr(struct device
static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
{
struct platform_device *pdev = of_find_device_by_node(np);
+ struct nvmem_cell *cell;
+ const void *mac;
+ size_t len;
int ret;
- if (!pdev)
- return -ENODEV;
+ /* Try lookup by device first, there might be a nvmem_cell_lookup
+ * associated with a given device.
+ */
+ if (pdev) {
+ ret = nvmem_get_mac_address(&pdev->dev, addr);
+ put_device(&pdev->dev);
+ return ret;
+ }
+
+ cell = of_nvmem_cell_get(np, "mac-address");
+ if (IS_ERR(cell))
+ return PTR_ERR(cell);
+
+ mac = nvmem_cell_read(cell, &len);
+ nvmem_cell_put(cell);
+
+ if (IS_ERR(mac))
+ return PTR_ERR(mac);
+
+ if (len != ETH_ALEN || !is_valid_ether_addr(mac)) {
+ kfree(mac);
+ return -EINVAL;
+ }
- ret = nvmem_get_mac_address(&pdev->dev, addr);
- put_device(&pdev->dev);
+ memcpy(addr, mac, ETH_ALEN);
+ kfree(mac);
- return ret;
+ return 0;
}
/**

View File

@ -0,0 +1,77 @@
From f10843e04a075202dbb39dfcee047e3a2fdf5a8d Mon Sep 17 00:00:00 2001
From: Michael Walle <michael@walle.cc>
Date: Mon, 12 Apr 2021 19:47:18 +0200
Subject: of: net: fix of_get_mac_addr_nvmem() for non-platform devices
of_get_mac_address() already supports fetching the MAC address by an
nvmem provider. But until now, it was just working for platform devices.
Esp. it was not working for DSA ports and PCI devices. It gets more
common that PCI devices have a device tree binding since SoCs contain
integrated root complexes.
Use the nvmem of_* binding to fetch the nvmem cells by a struct
device_node. We still have to try to read the cell by device first
because there might be a nvmem_cell_lookup associated with that device.
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
---
drivers/of/of_net.c | 35 ++++++++++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 5 deletions(-)
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -11,6 +11,7 @@
#include <linux/phy.h>
#include <linux/export.h>
#include <linux/device.h>
+#include <linux/nvmem-consumer.h>
/**
* of_get_phy_mode - Get phy mode for given device_node
@@ -53,15 +54,39 @@ static int of_get_mac_addr(struct device
static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
{
struct platform_device *pdev = of_find_device_by_node(np);
+ struct nvmem_cell *cell;
+ const void *mac;
+ size_t len;
int ret;
- if (!pdev)
- return -ENODEV;
+ /* Try lookup by device first, there might be a nvmem_cell_lookup
+ * associated with a given device.
+ */
+ if (pdev) {
+ ret = nvmem_get_mac_address(&pdev->dev, addr);
+ put_device(&pdev->dev);
+ return ret;
+ }
+
+ cell = of_nvmem_cell_get(np, "mac-address");
+ if (IS_ERR(cell))
+ return PTR_ERR(cell);
+
+ mac = nvmem_cell_read(cell, &len);
+ nvmem_cell_put(cell);
+
+ if (IS_ERR(mac))
+ return PTR_ERR(mac);
+
+ if (len != ETH_ALEN || !is_valid_ether_addr(mac)) {
+ kfree(mac);
+ return -EINVAL;
+ }
- ret = nvmem_get_mac_address(&pdev->dev, addr);
- put_device(&pdev->dev);
+ memcpy(addr, mac, ETH_ALEN);
+ kfree(mac);
- return ret;
+ return 0;
}
/**

View File

@ -1,27 +0,0 @@
From c94b2cfd25c282e2974accc1b07da98ae7139b47 Mon Sep 17 00:00:00 2001
From: Ansuel Smith <ansuelsmth@gmail.com>
Date: Fri, 23 Jul 2021 12:14:33 +0200
Subject: [PATCH 1/2] drivers: net: mediatek: register of_platform for every
port
Currently the nvmem framework require the devicenode to be registred on
the of_platform or of_get_mac_address fail to get the macaddress if
defined using an nvmem cell. Fix this by registrering these special node
so they can be found by of_find_device_by_node.
Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 ++
1 file changed, 2 insertions(+)
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -3005,6 +3005,8 @@ static int mtk_add_mac(struct mtk_eth *e
eth->netdev[id]->dev.of_node = np;
eth->netdev[id]->max_mtu = MTK_MAX_RX_LENGTH - MTK_RX_ETH_HLEN;
+
+ of_platform_device_create(np, NULL, NULL);
return 0;

View File

@ -1,35 +0,0 @@
From 8bab551f44204fc5d43977063cd704112c17c750 Mon Sep 17 00:00:00 2001
From: Ansuel Smith <ansuelsmth@gmail.com>
Date: Fri, 23 Jul 2021 12:17:27 +0200
Subject: [PATCH 2/2] dsa: register every port with of_platform
The declaration of a different mac-addr using the nvmem framework is
currently broken. The dsa code use the generic of_get_mac_address where
the nvmem function require the device node to be registred in the
of_platform to be found by of_find_device_by_node. Register every port
in the of_platform so they can corrently found and a custom mac-addr can
correctly be declared using a nvmem-cell declared in the dts.
Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
net/dsa/dsa2.c | 2 +
1 file changed, 2 insertion(+)
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -14,6 +14,7 @@
#include <linux/rtnetlink.h>
#include <linux/of.h>
#include <linux/of_net.h>
+#include <linux/of_platform.h>
#include <net/devlink.h>
#include "dsa_priv.h"
@@ -288,6 +289,7 @@ static int dsa_port_setup(struct dsa_por
break;
case DSA_PORT_TYPE_USER:
+ of_platform_device_create(dp->dn, NULL, NULL);
dp->mac = of_get_mac_address(dp->dn);
err = dsa_slave_create(dp);
if (err)

View File

@ -1,27 +0,0 @@
From c94b2cfd25c282e2974accc1b07da98ae7139b47 Mon Sep 17 00:00:00 2001
From: Ansuel Smith <ansuelsmth@gmail.com>
Date: Fri, 23 Jul 2021 12:14:33 +0200
Subject: [PATCH 1/2] drivers: net: mediatek: register of_platform for every
port
Currently the nvmem framework require the devicenode to be registred on
the of_platform or of_get_mac_address fail to get the macaddress if
defined using an nvmem cell. Fix this by registrering these special node
so they can be found by of_find_device_by_node.
Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 ++
1 file changed, 2 insertions(+)
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -3034,6 +3034,8 @@ static int mtk_add_mac(struct mtk_eth *e
eth->netdev[id]->dev.of_node = np;
eth->netdev[id]->max_mtu = MTK_MAX_RX_LENGTH - MTK_RX_ETH_HLEN;
+
+ of_platform_device_create(np, NULL, NULL);
return 0;

View File

@ -1,35 +0,0 @@
From 8bab551f44204fc5d43977063cd704112c17c750 Mon Sep 17 00:00:00 2001
From: Ansuel Smith <ansuelsmth@gmail.com>
Date: Fri, 23 Jul 2021 12:17:27 +0200
Subject: [PATCH 2/2] dsa: register every port with of_platform
The declaration of a different mac-addr using the nvmem framework is
currently broken. The dsa code use the generic of_get_mac_address where
the nvmem function require the device node to be registred in the
of_platform to be found by of_find_device_by_node. Register every port
in the of_platform so they can corrently found and a custom mac-addr can
correctly be declared using a nvmem-cell declared in the dts.
Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
net/dsa/dsa2.c | 2 +
1 file changed, 2 insertion(+)
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -14,6 +14,7 @@
#include <linux/rtnetlink.h>
#include <linux/of.h>
#include <linux/of_net.h>
+#include <linux/of_platform.h>
#include <net/devlink.h>
#include "dsa_priv.h"
@@ -318,6 +319,7 @@ static int dsa_port_setup(struct dsa_por
break;
devlink_port_registered = true;
+ of_platform_device_create(dp->dn, NULL, NULL);
dp->mac = of_get_mac_address(dp->dn);
err = dsa_slave_create(dp);
if (err)

View File

@ -17,28 +17,19 @@ Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -11,6 +11,7 @@
#include <linux/phy.h>
@@ -12,6 +12,7 @@
#include <linux/export.h>
#include <linux/device.h>
#include <linux/nvmem-consumer.h>
+#include <linux/mtd/mtd.h>
/**
* of_get_phy_mode - Get phy mode for given device_node
@@ -45,7 +46,7 @@ int of_get_phy_mode(struct device_node *
}
EXPORT_SYMBOL_GPL(of_get_phy_mode);
-static const void *of_get_mac_addr(struct device_node *np, const char *name)
+static void *of_get_mac_addr(struct device_node *np, const char *name)
{
struct property *pp = of_find_property(np, name, NULL);
@@ -78,6 +79,55 @@ static const void *of_get_mac_addr_nvmem
return mac;
@@ -95,6 +96,52 @@ static int of_get_mac_addr_nvmem(struct
return 0;
}
+static const void *of_get_mac_address_mtd(struct device_node *np)
+static int of_get_mac_address_mtd(struct device_node *np, u8 *addr)
+{
+#ifdef CONFIG_MTD
+ struct platform_device *pdev = of_find_device_by_node(np);
@ -50,18 +41,17 @@ Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
+ const __be32 *list;
+ phandle phandle;
+ u8 mac[ETH_ALEN];
+ void *addr;
+
+ list = of_get_property(np, "mtd-mac-address", &size);
+ if (!list || (size != (2 * sizeof(*list))))
+ return NULL;
+ return -ENODEV;
+
+ phandle = be32_to_cpup(list++);
+ if (phandle)
+ mtd_np = of_find_node_by_phandle(phandle);
+
+ if (!mtd_np)
+ return NULL;
+ return -ENODEV;
+
+ part = of_get_property(mtd_np, "label", NULL);
+ if (!part)
@ -69,28 +59,26 @@ Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
+
+ mtd = get_mtd_device_nm(part);
+ if (IS_ERR(mtd))
+ return NULL;
+ return -ENODEV;
+
+ ret = mtd_read(mtd, be32_to_cpup(list), 6, &retlen, mac);
+ put_mtd_device(mtd);
+
+ if (!is_valid_ether_addr(mac))
+ return NULL;
+ return -EINVAL;
+
+ addr = devm_kmemdup(&pdev->dev, mac, ETH_ALEN, GFP_KERNEL);
+ if (!addr)
+ return ERR_PTR(-ENOMEM);
+ memcpy(addr, mac, ETH_ALEN);
+
+ return addr;
+ return 0;
+#endif
+ return NULL;
+ return -EINVAL;
+}
+
+
/**
* Search the device tree for the best MAC address to use. 'mac-address' is
* checked first, because that is supposed to contain to "most recent" MAC
@@ -98,6 +148,10 @@ static const void *of_get_mac_addr_nvmem
@@ -115,6 +161,10 @@ static int of_get_mac_addr_nvmem(struct
* this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
* but is all zeros.
*
@ -98,17 +86,17 @@ Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
+ * If a mtd-mac-address property exists, try to fetch the MAC address from the
+ * specified mtd device.
+ *
* Return: Will be a valid pointer on success and ERR_PTR in case of error.
* Return: 0 on success and errno in case of error.
*/
const void *of_get_mac_address(struct device_node *np)
@@ -116,6 +170,10 @@ const void *of_get_mac_address(struct de
if (addr)
return addr;
int of_get_mac_address(struct device_node *np, u8 *addr)
@@ -136,6 +186,10 @@ int of_get_mac_address(struct device_nod
if (!ret)
return 0;
+ addr = of_get_mac_address_mtd(np);
+ if (addr)
+ return addr;
+ ret = of_get_mac_address_mtd(np, addr);
+ if (!ret)
+ return 0;
+
return of_get_mac_addr_nvmem(np);
return of_get_mac_addr_nvmem(np, addr);
}
EXPORT_SYMBOL(of_get_mac_address);

View File

@ -20,52 +20,7 @@ Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -55,31 +55,36 @@ static void *of_get_mac_addr(struct devi
return NULL;
}
-static const void *of_get_mac_addr_nvmem(struct device_node *np)
+static void *of_get_mac_addr_nvmem(struct device_node *np, int *err)
{
int ret;
- const void *mac;
+ void *mac;
u8 nvmem_mac[ETH_ALEN];
struct platform_device *pdev = of_find_device_by_node(np);
- if (!pdev)
- return ERR_PTR(-ENODEV);
+ if (!pdev) {
+ *err = -ENODEV;
+ return NULL;
+ }
ret = nvmem_get_mac_address(&pdev->dev, &nvmem_mac);
if (ret) {
put_device(&pdev->dev);
- return ERR_PTR(ret);
+ *err = ret;
+ return NULL;
}
mac = devm_kmemdup(&pdev->dev, nvmem_mac, ETH_ALEN, GFP_KERNEL);
put_device(&pdev->dev);
- if (!mac)
- return ERR_PTR(-ENOMEM);
+ if (!mac) {
+ *err = -ENOMEM;
+ return NULL;
+ }
return mac;
}
-static const void *of_get_mac_address_mtd(struct device_node *np)
+static void *of_get_mac_address_mtd(struct device_node *np)
{
#ifdef CONFIG_MTD
struct platform_device *pdev = of_find_device_by_node(np);
@@ -152,28 +157,54 @@ static const void *of_get_mac_address_mt
@@ -165,31 +165,56 @@ static int of_get_mac_address_mtd(struct
* If a mtd-mac-address property exists, try to fetch the MAC address from the
* specified mtd device.
*
@ -77,52 +32,53 @@ Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
+ * not overflow to other bytes if the increment is over 255.
+ * (example 00:01:02:03:04:ff + 1 == 00:01:02:03:04:00)
+ *
* Return: Will be a valid pointer on success and ERR_PTR in case of error.
* Return: 0 on success and errno in case of error.
*/
const void *of_get_mac_address(struct device_node *np)
int of_get_mac_address(struct device_node *np, u8 *addr)
{
- const void *addr;
+ u32 inc_idx, mac_inc;
+ int ret = 0;
+ u8 *addr;
+
int ret;
+ /* Check first if the increment byte is present and valid.
+ * If not set assume to increment the last byte if found.
+ */
+ if (of_property_read_u32(np, "mac-address-increment-byte", &inc_idx))
+ inc_idx = 5;
+ if (inc_idx < 3 || inc_idx > 5)
+ return ERR_PTR(-EINVAL);
+ return -EINVAL;
+
if (!np)
return -ENODEV;
addr = of_get_mac_addr(np, "mac-address");
if (addr)
- return addr;
ret = of_get_mac_addr(np, "mac-address", addr);
if (!ret)
- return 0;
+ goto found;
addr = of_get_mac_addr(np, "local-mac-address");
if (addr)
- return addr;
ret = of_get_mac_addr(np, "local-mac-address", addr);
if (!ret)
- return 0;
+ goto found;
addr = of_get_mac_addr(np, "address");
if (addr)
- return addr;
ret = of_get_mac_addr(np, "address", addr);
if (!ret)
- return 0;
+ goto found;
addr = of_get_mac_address_mtd(np);
if (addr)
- return addr;
ret = of_get_mac_address_mtd(np, addr);
if (!ret)
- return 0;
+ goto found;
+
+ addr = of_get_mac_addr_nvmem(np, &ret);
+ ret = of_get_mac_addr_nvmem(np, addr);
+ if (ret)
+ return ERR_PTR(ret);
+ return ret;
+
+found:
+ if (!of_property_read_u32(np, "mac-address-increment", &mac_inc))
+ addr[inc_idx] += mac_inc;
- return of_get_mac_addr_nvmem(np);
+ return addr;
- return of_get_mac_addr_nvmem(np, addr);
+ return ret;
}
EXPORT_SYMBOL(of_get_mac_address);

View File

@ -1,19 +1,16 @@
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -132,6 +132,33 @@ static void *of_get_mac_address_mtd(stru
return NULL;
@@ -132,6 +132,30 @@ static void *of_get_mac_address_mtd(stru
return -EINVAL;
}
+static int of_add_mac_address(struct device_node *np, u8* addr)
+{
+ struct property *prop;
+ u8 *np_addr;
+
+ np_addr = of_get_mac_addr(np, "mac-address");
+ if (np_addr) {
+ memcpy(np_addr, addr, ETH_ALEN);
+ return 0;
+ }
+ prop = of_find_property(np, "mac-address", NULL);
+ if (prop)
+ kfree(prop);
+
+ prop = kzalloc(sizeof(*prop), GFP_KERNEL);
+ if (!prop)
@ -39,6 +36,6 @@
addr[inc_idx] += mac_inc;
+ of_add_mac_address(np, addr);
return addr;
return ret;
}
EXPORT_SYMBOL(of_get_mac_address);

View File

@ -17,28 +17,19 @@ Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -11,6 +11,7 @@
#include <linux/phy.h>
@@ -12,6 +12,7 @@
#include <linux/export.h>
#include <linux/device.h>
#include <linux/nvmem-consumer.h>
+#include <linux/mtd/mtd.h>
/**
* of_get_phy_mode - Get phy mode for given device_node
@@ -39,7 +40,7 @@ int of_get_phy_mode(struct device_node *
}
EXPORT_SYMBOL_GPL(of_get_phy_mode);
-static const void *of_get_mac_addr(struct device_node *np, const char *name)
+static void *of_get_mac_addr(struct device_node *np, const char *name)
{
struct property *pp = of_find_property(np, name, NULL);
@@ -72,6 +73,55 @@ static const void *of_get_mac_addr_nvmem
return mac;
@@ -95,6 +96,52 @@ static int of_get_mac_addr_nvmem(struct
return 0;
}
+static const void *of_get_mac_address_mtd(struct device_node *np)
+static int of_get_mac_address_mtd(struct device_node *np, u8 *addr)
+{
+#ifdef CONFIG_MTD
+ struct platform_device *pdev = of_find_device_by_node(np);
@ -50,18 +41,17 @@ Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
+ const __be32 *list;
+ phandle phandle;
+ u8 mac[ETH_ALEN];
+ void *addr;
+
+ list = of_get_property(np, "mtd-mac-address", &size);
+ if (!list || (size != (2 * sizeof(*list))))
+ return NULL;
+ return -ENODEV;
+
+ phandle = be32_to_cpup(list++);
+ if (phandle)
+ mtd_np = of_find_node_by_phandle(phandle);
+
+ if (!mtd_np)
+ return NULL;
+ return -ENODEV;
+
+ part = of_get_property(mtd_np, "label", NULL);
+ if (!part)
@ -69,28 +59,26 @@ Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
+
+ mtd = get_mtd_device_nm(part);
+ if (IS_ERR(mtd))
+ return NULL;
+ return -ENODEV;
+
+ ret = mtd_read(mtd, be32_to_cpup(list), 6, &retlen, mac);
+ put_mtd_device(mtd);
+
+ if (!is_valid_ether_addr(mac))
+ return NULL;
+ return -EINVAL;
+
+ addr = devm_kmemdup(&pdev->dev, mac, ETH_ALEN, GFP_KERNEL);
+ if (!addr)
+ return ERR_PTR(-ENOMEM);
+ memcpy(addr, mac, ETH_ALEN);
+
+ return addr;
+ return 0;
+#endif
+ return NULL;
+ return -EINVAL;
+}
+
+
/**
* Search the device tree for the best MAC address to use. 'mac-address' is
* checked first, because that is supposed to contain to "most recent" MAC
@@ -92,6 +142,10 @@ static const void *of_get_mac_addr_nvmem
@@ -115,6 +161,10 @@ static int of_get_mac_addr_nvmem(struct
* this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
* but is all zeros.
*
@ -98,17 +86,17 @@ Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
+ * If a mtd-mac-address property exists, try to fetch the MAC address from the
+ * specified mtd device.
+ *
* Return: Will be a valid pointer on success and ERR_PTR in case of error.
* Return: 0 on success and errno in case of error.
*/
const void *of_get_mac_address(struct device_node *np)
@@ -110,6 +164,10 @@ const void *of_get_mac_address(struct de
if (addr)
return addr;
int of_get_mac_address(struct device_node *np, u8 *addr)
@@ -136,6 +186,10 @@ int of_get_mac_address(struct device_nod
if (!ret)
return 0;
+ addr = of_get_mac_address_mtd(np);
+ if (addr)
+ return addr;
+ ret = of_get_mac_address_mtd(np, addr);
+ if (!ret)
+ return 0;
+
return of_get_mac_addr_nvmem(np);
return of_get_mac_addr_nvmem(np, addr);
}
EXPORT_SYMBOL(of_get_mac_address);

View File

@ -20,52 +20,7 @@ Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -49,31 +49,36 @@ static void *of_get_mac_addr(struct devi
return NULL;
}
-static const void *of_get_mac_addr_nvmem(struct device_node *np)
+static void *of_get_mac_addr_nvmem(struct device_node *np, int *err)
{
int ret;
- const void *mac;
+ void *mac;
u8 nvmem_mac[ETH_ALEN];
struct platform_device *pdev = of_find_device_by_node(np);
- if (!pdev)
- return ERR_PTR(-ENODEV);
+ if (!pdev) {
+ *err = -ENODEV;
+ return NULL;
+ }
ret = nvmem_get_mac_address(&pdev->dev, &nvmem_mac);
if (ret) {
put_device(&pdev->dev);
- return ERR_PTR(ret);
+ *err = ret;
+ return NULL;
}
mac = devm_kmemdup(&pdev->dev, nvmem_mac, ETH_ALEN, GFP_KERNEL);
put_device(&pdev->dev);
- if (!mac)
- return ERR_PTR(-ENOMEM);
+ if (!mac) {
+ *err = -ENOMEM;
+ return NULL;
+ }
return mac;
}
-static const void *of_get_mac_address_mtd(struct device_node *np)
+static void *of_get_mac_address_mtd(struct device_node *np)
{
#ifdef CONFIG_MTD
struct platform_device *pdev = of_find_device_by_node(np);
@@ -146,28 +151,54 @@ static const void *of_get_mac_address_mt
@@ -165,31 +165,56 @@ static int of_get_mac_address_mtd(struct
* If a mtd-mac-address property exists, try to fetch the MAC address from the
* specified mtd device.
*
@ -77,52 +32,53 @@ Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
+ * not overflow to other bytes if the increment is over 255.
+ * (example 00:01:02:03:04:ff + 1 == 00:01:02:03:04:00)
+ *
* Return: Will be a valid pointer on success and ERR_PTR in case of error.
* Return: 0 on success and errno in case of error.
*/
const void *of_get_mac_address(struct device_node *np)
int of_get_mac_address(struct device_node *np, u8 *addr)
{
- const void *addr;
+ u32 inc_idx, mac_inc;
+ int ret = 0;
+ u8 *addr;
+
int ret;
+ /* Check first if the increment byte is present and valid.
+ * If not set assume to increment the last byte if found.
+ */
+ if (of_property_read_u32(np, "mac-address-increment-byte", &inc_idx))
+ inc_idx = 5;
+ if (inc_idx < 3 || inc_idx > 5)
+ return ERR_PTR(-EINVAL);
+ return -EINVAL;
+
if (!np)
return -ENODEV;
addr = of_get_mac_addr(np, "mac-address");
if (addr)
- return addr;
ret = of_get_mac_addr(np, "mac-address", addr);
if (!ret)
- return 0;
+ goto found;
addr = of_get_mac_addr(np, "local-mac-address");
if (addr)
- return addr;
ret = of_get_mac_addr(np, "local-mac-address", addr);
if (!ret)
- return 0;
+ goto found;
addr = of_get_mac_addr(np, "address");
if (addr)
- return addr;
ret = of_get_mac_addr(np, "address", addr);
if (!ret)
- return 0;
+ goto found;
addr = of_get_mac_address_mtd(np);
if (addr)
- return addr;
ret = of_get_mac_address_mtd(np, addr);
if (!ret)
- return 0;
+ goto found;
+
+ addr = of_get_mac_addr_nvmem(np, &ret);
+ ret = of_get_mac_addr_nvmem(np, addr);
+ if (ret)
+ return ERR_PTR(ret);
+ return ret;
+
+found:
+ if (!of_property_read_u32(np, "mac-address-increment", &mac_inc))
+ addr[inc_idx] += mac_inc;
- return of_get_mac_addr_nvmem(np);
+ return addr;
- return of_get_mac_addr_nvmem(np, addr);
+ return ret;
}
EXPORT_SYMBOL(of_get_mac_address);

View File

@ -1,19 +1,16 @@
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -126,6 +126,33 @@ static void *of_get_mac_address_mtd(stru
return NULL;
@@ -132,6 +132,30 @@ static void *of_get_mac_address_mtd(stru
return -EINVAL;
}
+static int of_add_mac_address(struct device_node *np, u8* addr)
+{
+ struct property *prop;
+ u8 *np_addr;
+
+ np_addr = of_get_mac_addr(np, "mac-address");
+ if (np_addr) {
+ memcpy(np_addr, addr, ETH_ALEN);
+ return 0;
+ }
+ prop = of_find_property(np, "mac-address", NULL);
+ if (prop)
+ kfree(prop);
+
+ prop = kzalloc(sizeof(*prop), GFP_KERNEL);
+ if (!prop)
@ -34,11 +31,11 @@
/**
* Search the device tree for the best MAC address to use. 'mac-address' is
@@ -199,6 +226,7 @@ found:
@@ -205,6 +232,7 @@ found:
if (!of_property_read_u32(np, "mac-address-increment", &mac_inc))
addr[inc_idx] += mac_inc;
+ of_add_mac_address(np, addr);
return addr;
return ret;
}
EXPORT_SYMBOL(of_get_mac_address);

View File

@ -905,8 +905,6 @@ static int edma_axi_probe(struct platform_device *pdev)
}
for_each_available_child_of_node(np, pnp) {
const char *mac_addr;
/* this check is needed if parent and daughter dts have
* different number of gmac nodes
*/
@ -915,9 +913,7 @@ static int edma_axi_probe(struct platform_device *pdev)
break;
}
mac_addr = of_get_mac_address(pnp);
if (!IS_ERR(mac_addr))
memcpy(edma_netdev[idx_mac]->dev_addr, mac_addr, ETH_ALEN);
of_get_mac_address(pnp, edma_netdev[idx_mac]->dev_addr);
idx_mac++;
}

View File

@ -721,7 +721,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
netif_trans_update(dev);
netif_wake_queue(dev);
return;
@@ -618,14 +822,19 @@ static const struct net_device_ops ltq_e
@@ -618,14 +822,18 @@ static const struct net_device_ops ltq_e
.ndo_tx_timeout = ltq_etop_tx_timeout,
};
@ -733,7 +733,6 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
struct ltq_etop_priv *priv;
- struct resource *res;
+ struct resource *res, *gbit_res, irqres[2];
+ const u8 *mac;
int err;
- int i;
+
@ -745,7 +744,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
@@ -651,31 +860,64 @@ ltq_etop_probe(struct platform_device *p
@@ -651,31 +860,62 @@ ltq_etop_probe(struct platform_device *p
goto err_out;
}
@ -785,9 +784,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
+ if (err)
+ pr_err("Can't find phy-mode for port\n");
+
+ mac = of_get_mac_address(pdev->dev.of_node);
+ if (mac)
+ memcpy(priv->mac, mac, ETH_ALEN);
+ of_get_mac_address(pdev->dev.of_node, priv->mac);
+
+ priv->clk_ppe = clk_get(&pdev->dev, NULL);
+ if (IS_ERR(priv->clk_ppe))

View File

@ -721,7 +721,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
netif_trans_update(dev);
netif_wake_queue(dev);
return;
@@ -625,14 +829,19 @@ static const struct net_device_ops ltq_e
@@ -625,14 +829,18 @@ static const struct net_device_ops ltq_e
.ndo_tx_timeout = ltq_etop_tx_timeout,
};
@ -733,7 +733,6 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
struct ltq_etop_priv *priv;
- struct resource *res;
+ struct resource *res, *gbit_res, irqres[2];
+ const u8 *mac;
int err;
- int i;
+
@ -745,7 +744,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
@@ -658,31 +867,62 @@ ltq_etop_probe(struct platform_device *p
@@ -658,31 +867,60 @@ ltq_etop_probe(struct platform_device *p
goto err_out;
}
@ -783,9 +782,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
+ priv->rx_irq = irqres[1].start;
+ priv->mii_mode = of_get_phy_mode(pdev->dev.of_node);
+
+ mac = of_get_mac_address(pdev->dev.of_node);
+ if (mac)
+ memcpy(priv->mac, mac, ETH_ALEN);
+ of_get_mac_address(pdev->dev.of_node, priv->mac);
+
+ priv->clk_ppe = clk_get(&pdev->dev, NULL);
+ if (IS_ERR(priv->clk_ppe))

View File

@ -10514,7 +10514,7 @@ Signed-off-by: Madalin Bucur <madalin.bucur@nxp.com>
+module_exit(dpa_ptp_unload);
--- /dev/null
+++ b/drivers/net/ethernet/freescale/sdk_dpaa/mac-api.c
@@ -0,0 +1,909 @@
@@ -0,0 +1,907 @@
+/* Copyright 2008-2012 Freescale Semiconductor, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
@ -11582,7 +11582,6 @@ Signed-off-by: Madalin Bucur <madalin.bucur@nxp.com>
+ struct mac_device *mac_dev;
+ struct platform_device *of_dev;
+ struct resource res;
+ const uint8_t *mac_addr;
+ const char *char_prop;
+ int nph;
+ u32 cell_index;
@ -11701,14 +11700,13 @@ Signed-off-by: Madalin Bucur <madalin.bucur@nxp.com>
+ mac_dev->cell_index -= 8;
+
+ /* Get the MAC address */
+ mac_addr = of_get_mac_address(mac_node);
+ if (unlikely(mac_addr == NULL)) {
+ of_get_mac_address(mac_node, mac_dev->addr);
+ if (unlikely(!is_valid_ether_addr(mac_dev->addr))) {
+ dev_err(dev, "of_get_mac_address(%s) failed\n",
+ mac_node->full_name);
+ _errno = -EINVAL;
+ goto _return_dev_set_drvdata;
+ }
+ memcpy(mac_dev->addr, mac_addr, sizeof(mac_dev->addr));
+
+ /* Verify the number of port handles */
+ nph = of_count_phandle_with_args(mac_node, "fsl,fman-ports", NULL);

View File

@ -6638,7 +6638,7 @@ Signed-off-by: Anjaneyulu Jagarlmudi <anji.jagarlmudi@nxp.com>
+}
--- /dev/null
+++ b/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
@@ -0,0 +1,394 @@
@@ -0,0 +1,388 @@
+/*
+ * Copyright 2015-2016 Freescale Semiconductor, Inc.
+ * Copyright 2017 NXP
@ -6680,7 +6680,6 @@ Signed-off-by: Anjaneyulu Jagarlmudi <anji.jagarlmudi@nxp.com>
+ int size;
+ int ii = 0, phy_id = 0;
+ const u32 *addr;
+ const void *mac_addr;
+
+ for (ii = 0; ii < if_cnt; ii++) {
+ gem = of_get_next_child(parent, gem);
@ -6699,12 +6698,7 @@ Signed-off-by: Anjaneyulu Jagarlmudi <anji.jagarlmudi@nxp.com>
+
+ pdata->ls1012a_eth_pdata[port].gem_id = port;
+
+ mac_addr = of_get_mac_address(gem);
+
+ if (mac_addr) {
+ memcpy(pdata->ls1012a_eth_pdata[port].mac_addr, mac_addr,
+ ETH_ALEN);
+ }
+ of_get_mac_address(gem, pdata->ls1012a_eth_pdata[port].mac_addr);
+
+ pdata->ls1012a_eth_pdata[port].mii_config = of_get_phy_mode(gem);
+

View File

@ -33,15 +33,9 @@ Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
int size;
int ii = 0, phy_id = 0;
const u32 *addr;
@@ -49,18 +49,11 @@ static int pfe_get_gemac_if_proprties(st
pdata->ls1012a_eth_pdata[port].gem_id = port;
@@ -49,12 +49,6 @@ static int pfe_get_gemac_if_proprties(st
mac_addr = of_get_mac_address(gem);
-
if (mac_addr) {
memcpy(pdata->ls1012a_eth_pdata[port].mac_addr, mac_addr,
ETH_ALEN);
}
of_get_mac_address(gem, pdata->ls1012a_eth_pdata[port].mac_addr);
- pdata->ls1012a_eth_pdata[port].mii_config = of_get_phy_mode(gem);
-

View File

@ -30,9 +30,3 @@ Signed-off-by: Anji Jagarlmudi <anji.jagarlmudi@nxp.com>
pdata->ls1012a_eth_pdata[port].gem_id = port;
mac_addr = of_get_mac_address(gem);
- if (mac_addr) {
+ if (!IS_ERR_OR_NULL(mac_addr)) {
memcpy(pdata->ls1012a_eth_pdata[port].mac_addr, mac_addr,
ETH_ALEN);
}

View File

@ -12,20 +12,18 @@ Tested-by: Johannes Kimmel <fff@bareminimum.eu>
Signed-off-by: Roman Kuzmitskii <damex.pp@icloud.com>
--- a/drivers/staging/octeon/ethernet.c
+++ b/drivers/staging/octeon/ethernet.c
@@ -408,9 +408,12 @@ int cvm_oct_common_init(struct net_devic
@@ -408,7 +408,11 @@ int cvm_oct_common_init(struct net_devic
int cvm_oct_common_init(struct net_device *dev)
{
struct octeon_ethernet *priv = netdev_priv(dev);
const u8 *mac = NULL;
+ const u8 *label = NULL;
- if (priv->of_node)
+ if (priv->of_node) {
mac = of_get_mac_address(priv->of_node);
int ret;
+
+ if (priv->of_node)
+ label = of_get_property(priv->of_node, "label", NULL);
+ }
if (!IS_ERR_OR_NULL(mac))
ether_addr_copy(dev->dev_addr, mac);
ret = of_get_mac_address(priv->of_node, dev->dev_addr);
if (ret)
@@ -445,6 +448,9 @@ int cvm_oct_common_init(struct net_devic
if (dev->netdev_ops->ndo_stop)
dev->netdev_ops->ndo_stop(dev);

View File

@ -12,20 +12,18 @@ Tested-by: Johannes Kimmel <fff@bareminimum.eu>
Signed-off-by: Roman Kuzmitskii <damex.pp@icloud.com>
--- a/drivers/staging/octeon/ethernet.c
+++ b/drivers/staging/octeon/ethernet.c
@@ -408,9 +408,12 @@ int cvm_oct_common_init(struct net_devic
@@ -408,7 +408,11 @@ int cvm_oct_common_init(struct net_devic
int cvm_oct_common_init(struct net_device *dev)
{
struct octeon_ethernet *priv = netdev_priv(dev);
const u8 *mac = NULL;
+ const u8 *label = NULL;
- if (priv->of_node)
+ if (priv->of_node) {
mac = of_get_mac_address(priv->of_node);
int ret;
+
+ if (priv->of_node)
+ label = of_get_property(priv->of_node, "label", NULL);
+ }
if (!IS_ERR_OR_NULL(mac))
ether_addr_copy(dev->dev_addr, mac);
ret = of_get_mac_address(priv->of_node, dev->dev_addr);
if (ret)
@@ -445,6 +448,9 @@ int cvm_oct_common_init(struct net_devic
if (dev->netdev_ops->ndo_stop)
dev->netdev_ops->ndo_stop(dev);

View File

@ -1368,7 +1368,6 @@ static int __init fe_init(struct net_device *dev)
{
struct fe_priv *priv = netdev_priv(dev);
struct device_node *port;
const char *mac_addr;
int err;
if (priv->soc->reset_fe)
@ -1389,9 +1388,7 @@ static int __init fe_init(struct net_device *dev)
fe_reset_phy(priv);
mac_addr = of_get_mac_address(priv->dev->of_node);
if (!IS_ERR_OR_NULL(mac_addr))
ether_addr_copy(dev->dev_addr, mac_addr);
of_get_mac_address(priv->dev->of_node, dev->dev_addr);
/* If the mac address is invalid, use random mac address */
if (!is_valid_ether_addr(dev->dev_addr)) {

View File

@ -1968,7 +1968,6 @@ static int __init rtl838x_eth_probe(struct platform_device *pdev)
struct device_node *dn = pdev->dev.of_node;
struct rtl838x_eth_priv *priv;
struct resource *res, *mem;
const void *mac;
phy_interface_t phy_mode;
struct phylink *phylink;
int err = 0, i, rxrings, rxringlen;
@ -2089,10 +2088,9 @@ static int __init rtl838x_eth_probe(struct platform_device *pdev)
* 1) from device tree data
* 2) from internal registers set by bootloader
*/
mac = of_get_mac_address(pdev->dev.of_node);
if (!IS_ERR(mac)) {
memcpy(dev->dev_addr, mac, ETH_ALEN);
rtl838x_set_mac_hw(dev, (u8 *)mac);
of_get_mac_address(pdev->dev.of_node, dev->dev_addr);
if (is_valid_ether_addr(dev->dev_addr))) {
rtl838x_set_mac_hw(dev, (u8 *)dev->dev_addr);
} else {
dev->dev_addr[0] = (sw_r32(priv->r->mac) >> 8) & 0xff;
dev->dev_addr[1] = sw_r32(priv->r->mac) & 0xff;