lkml.org 
[lkml]   [2018]   [Nov]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 4.9 85/92] lan78xx: Read MAC address from DT if present
    Date
    4.9-stable review patch.  If anyone has any objections, please let me know.

    ------------------

    From: Phil Elwell <phil@raspberrypi.org>

    commit 760db29bdc97b73ff60b091315ad787b1deb5cf5 upstream.

    There is a standard mechanism for locating and using a MAC address from
    the Device Tree. Use this facility in the lan78xx driver to support
    applications without programmed EEPROM or OTP. At the same time,
    regularise the handling of the different address sources.

    Signed-off-by: Phil Elwell <phil@raspberrypi.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Tested-by: Paolo Pisati <p.pisati@gmail.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

    ---
    drivers/net/usb/lan78xx.c | 42 ++++++++++++++++++++----------------------
    1 file changed, 20 insertions(+), 22 deletions(-)

    --- a/drivers/net/usb/lan78xx.c
    +++ b/drivers/net/usb/lan78xx.c
    @@ -31,6 +31,7 @@
    #include <linux/mdio.h>
    #include <net/ip6_checksum.h>
    #include <linux/microchipphy.h>
    +#include <linux/of_net.h>
    #include "lan78xx.h"

    #define DRIVER_AUTHOR "WOOJUNG HUH <woojung.huh@microchip.com>"
    @@ -1644,34 +1645,31 @@ static void lan78xx_init_mac_address(str
    addr[5] = (addr_hi >> 8) & 0xFF;

    if (!is_valid_ether_addr(addr)) {
    - /* reading mac address from EEPROM or OTP */
    - if ((lan78xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
    - addr) == 0) ||
    - (lan78xx_read_otp(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
    - addr) == 0)) {
    - if (is_valid_ether_addr(addr)) {
    - /* eeprom values are valid so use them */
    - netif_dbg(dev, ifup, dev->net,
    - "MAC address read from EEPROM");
    - } else {
    - /* generate random MAC */
    - random_ether_addr(addr);
    - netif_dbg(dev, ifup, dev->net,
    - "MAC address set to random addr");
    - }
    -
    - addr_lo = addr[0] | (addr[1] << 8) |
    - (addr[2] << 16) | (addr[3] << 24);
    - addr_hi = addr[4] | (addr[5] << 8);
    -
    - ret = lan78xx_write_reg(dev, RX_ADDRL, addr_lo);
    - ret = lan78xx_write_reg(dev, RX_ADDRH, addr_hi);
    + if (!eth_platform_get_mac_address(&dev->udev->dev, addr)) {
    + /* valid address present in Device Tree */
    + netif_dbg(dev, ifup, dev->net,
    + "MAC address read from Device Tree");
    + } else if (((lan78xx_read_eeprom(dev, EEPROM_MAC_OFFSET,
    + ETH_ALEN, addr) == 0) ||
    + (lan78xx_read_otp(dev, EEPROM_MAC_OFFSET,
    + ETH_ALEN, addr) == 0)) &&
    + is_valid_ether_addr(addr)) {
    + /* eeprom values are valid so use them */
    + netif_dbg(dev, ifup, dev->net,
    + "MAC address read from EEPROM");
    } else {
    /* generate random MAC */
    random_ether_addr(addr);
    netif_dbg(dev, ifup, dev->net,
    "MAC address set to random addr");
    }
    +
    + addr_lo = addr[0] | (addr[1] << 8) |
    + (addr[2] << 16) | (addr[3] << 24);
    + addr_hi = addr[4] | (addr[5] << 8);
    +
    + ret = lan78xx_write_reg(dev, RX_ADDRL, addr_lo);
    + ret = lan78xx_write_reg(dev, RX_ADDRH, addr_hi);
    }

    ret = lan78xx_write_reg(dev, MAF_LO(0), addr_lo);

    \
     
     \ /
      Last update: 2018-11-29 15:52    [W:9.185 / U:0.104 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site