diff options
Diffstat (limited to 'drivers/net/ethernet/ethoc.c')
-rw-r--r-- | drivers/net/ethernet/ethoc.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/drivers/net/ethernet/ethoc.c b/drivers/net/ethernet/ethoc.c index 60f0e78..a381678 100644 --- a/drivers/net/ethernet/ethoc.c +++ b/drivers/net/ethernet/ethoc.c @@ -1,5 +1,5 @@ /* - * linux/drivers/net/ethoc.c + * linux/drivers/net/ethernet/ethoc.c * * Copyright (C) 2007-2008 Avionic Design Development GmbH * Copyright (C) 2008-2009 Avionic Design GmbH @@ -776,10 +776,16 @@ static int ethoc_set_mac_address(struct net_device *dev, void *addr) struct ethoc *priv = netdev_priv(dev); u8 *mac = (u8 *)addr; + if (!is_valid_ether_addr(mac)) + return -EADDRNOTAVAIL; + ethoc_write(priv, MAC_ADDR0, (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | (mac[5] << 0)); ethoc_write(priv, MAC_ADDR1, (mac[0] << 8) | (mac[1] << 0)); + memcpy(dev->dev_addr, mac, ETH_ALEN); + dev->addr_assign_type &= ~NET_ADDR_RANDOM; + return 0; } @@ -909,11 +915,11 @@ static int __devinit ethoc_probe(struct platform_device *pdev) unsigned int phy; int num_bd; int ret = 0; + bool random_mac = false; /* allocate networking device */ netdev = alloc_etherdev(sizeof(struct ethoc)); if (!netdev) { - dev_err(&pdev->dev, "cannot allocate network device\n"); ret = -ENOMEM; goto out; } @@ -1050,10 +1056,19 @@ static int __devinit ethoc_probe(struct platform_device *pdev) /* Check the MAC again for validity, if it still isn't choose and * program a random one. */ - if (!is_valid_ether_addr(netdev->dev_addr)) + if (!is_valid_ether_addr(netdev->dev_addr)) { random_ether_addr(netdev->dev_addr); + random_mac = true; + } + + ret = ethoc_set_mac_address(netdev, netdev->dev_addr); + if (ret) { + dev_err(&netdev->dev, "failed to set MAC address\n"); + goto error; + } - ethoc_set_mac_address(netdev, netdev->dev_addr); + if (random_mac) + netdev->addr_assign_type |= NET_ADDR_RANDOM; /* register MII bus */ priv->mdio = mdiobus_alloc(); |