Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
drivers/net/ethernet/stmicro: add generating MAC address from CPU ser…
…ial number if MAC address is not present
  • Loading branch information
kszaq authored and Adam Green committed May 11, 2018
1 parent f8335ed commit d3db126
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
Expand Up @@ -59,6 +59,9 @@
#endif
#include <linux/reset.h>
#include <linux/amlogic/securitykey.h>
#ifdef CONFIG_AMLOGIC_CPU_INFO
#include <linux/amlogic/cpu_version.h>
#endif

extern unsigned int g_mac_addr_setup;

Expand Down Expand Up @@ -2426,18 +2429,38 @@ static int stmmac_open(struct net_device *dev)

int ret = 0;

#ifdef CONFIG_AMLOGIC_CPU_INFO
static const u8 def_mac[] = {0x00, 0x15, 0x18, 0x01, 0x81, 0x31};
unsigned int low0, low1, high0, high1;
u8 buf[6];
#endif

if (g_mac_addr_setup == 0) {
#if defined (CONFIG_AML_NAND_KEY) || defined (CONFIG_SECURITYKEY)
ret = read_mac_from_nand(dev);
if (ret < 0)
#endif
{
#if defined CONFIG_EFUSE
efuse_get_mac(dev->dev_addr);
ret = efuse_get_mac(dev->dev_addr);
#endif
}
}

#ifdef CONFIG_AMLOGIC_CPU_INFO
if (ether_addr_equal(priv->dev->dev_addr, def_mac) ||
!is_valid_ether_addr(priv->dev->dev_addr) ||
ret < 0) {
printk("%s: generate MAC from CPU serial number\n", __func__);
cpuinfo_get_chipid(&low0, &low1, &high0, &high1);
memcpy(buf, &low0, 6);
buf[0] &= 0xfe; /* clear multicast bit */
buf[0] |= 0x02; /* set local assignment bit (IEEE802) */
printk("%s: generated MAC address: %pM\n", __func__, buf);
ether_addr_copy(dev->dev_addr, buf);
}
#endif

stmmac_check_ether_addr(priv);

if (priv->pcs != STMMAC_PCS_RGMII && priv->pcs != STMMAC_PCS_TBI &&
Expand Down

0 comments on commit d3db126

Please sign in to comment.