Received: by 10.192.165.156 with SMTP id m28csp1996290imm; Thu, 12 Apr 2018 07:02:39 -0700 (PDT) X-Google-Smtp-Source: AIpwx48UWL5fA+uqjjWedgCltYH0o+O+ZW9Hd1bpN0Mb4M43+D4dO+RzDd24AF4ELhajg70Ar1P0 X-Received: by 2002:a17:902:d681:: with SMTP id v1-v6mr1244311ply.120.1523541759345; Thu, 12 Apr 2018 07:02:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523541759; cv=none; d=google.com; s=arc-20160816; b=SKAI+brjligAxus9BpCc9lB+RQuCDVLRHWRGwroe3HqjGu8BWsQPIkfubnZDCXtlay vyt4NG0SGWFQUaijof5clfJiAdEhKxmZzzmPf2+9pgMb3pDkHXyKRkl8DeGkWRQ8v/6I 9iE5SbNBU0xLId6qUc/SP2KiCw3WMAgYFLvUz0waZ3cZfym2pFkoGLJ5TJ8AQyZ0H0Ed BUIOFklodVZ/7zBIdSZzRILiIOXXaKbCPuqj5V5emBwgZI4nic0qmgqn76Aog6JlrGzK WHuWOtFymLqXqB60X3b20hoP0v3oJhHedCJguAW5fvyedx7Ro4QgU53UbZ3HgonHInhN GXPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-signature :arc-authentication-results; bh=ZkQPYglmMf7WlOZMSJfnhEauQd7yT1YXjmkBGOPdi/8=; b=kKvGHGCPoZprCXYtGpwBUHCLWIYPByVkWUnX7nygJXtySLG3h7tphHuLmF9Qw2wQX9 ArfAqV4kijGzgbOeID8yWAkQEXTSAa4sbZYiNtheck/oJ862PteOjx2CXOKFw0c4qxVw gUJL+vcLB9l/Njlua6F5PjOLRqvIbFakzbcXcQctq6nt9Tc7loXrOqqwdHJKEabprxY6 S9AnOi6D6JfiUeWZRLt0sjPkmJhNXEXPsJ4CliimUmGcjZpJfEGGsDQZuSUKt2UIMsL3 LXtPEOnLZ07aa5ZKZtm1MdS/Gy2+4ytbIXQYZjXjs62a0Pyv51Wue4RwmfD5pzadO7Fz WNEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@raspberrypi.org header.s=pp header.b=MZBNz9Lo; dkim=pass header.i=@raspberrypi-org.20150623.gappssmtp.com header.s=20150623 header.b=JA1iweld; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k185si2300789pgk.2.2018.04.12.07.01.58; Thu, 12 Apr 2018 07:02:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@raspberrypi.org header.s=pp header.b=MZBNz9Lo; dkim=pass header.i=@raspberrypi-org.20150623.gappssmtp.com header.s=20150623 header.b=JA1iweld; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753056AbeDLN5W (ORCPT + 99 others); Thu, 12 Apr 2018 09:57:22 -0400 Received: from mx08-00252a01.pphosted.com ([91.207.212.211]:40334 "EHLO mx08-00252a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752406AbeDLNzu (ORCPT ); Thu, 12 Apr 2018 09:55:50 -0400 Received: from pps.filterd (m0102629.ppops.net [127.0.0.1]) by mx08-00252a01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3CDsY1i012745 for ; Thu, 12 Apr 2018 14:55:49 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.org; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp; bh=ZkQPYglmMf7WlOZMSJfnhEauQd7yT1YXjmkBGOPdi/8=; b=MZBNz9Lo7R2OvwNPrywReiW8MVGSiX5oYTLkQ/hHzrfSCMryc8qIvLCiBa96K3iZpo6l pCdSW28003M4xOEFaM9Bkr5Am5sIYHbYUzVJm4w7Y1bR+YKnjmDXXfOrE1iK3T+vm7RQ 8afUsgYUPIk2ocCdpJOMRz9leFxjBqxZIbOfP0A3PaJQ3/E0V57kaJYMmIH8CzjPQlP1 YimBx4pnFIrGzJd+Xq4wW/CZt+V7RyrHVmtOU/jsFtV0W6vLluAuepb9xYUz85JFZFyj gZto16pVaZuo9iqUsutDe7JNywkZQ9tMviwh43EY0fFAWYm/cJbur+N+7/DnOM3FnA0H nw== Received: from mail-wm0-f72.google.com (mail-wm0-f72.google.com [74.125.82.72]) by mx08-00252a01.pphosted.com with ESMTP id 2h6trdtjre-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK) for ; Thu, 12 Apr 2018 14:55:49 +0100 Received: by mail-wm0-f72.google.com with SMTP id z83so2824472wmc.2 for ; Thu, 12 Apr 2018 06:55:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZkQPYglmMf7WlOZMSJfnhEauQd7yT1YXjmkBGOPdi/8=; b=JA1iweldOd4YbnuzVv9/+B9VXkEnJyDd6j+fVevrxiESrCrSIawJhRXaedmRtpsRcf dpYEZlD2gbJ4Y8Lri9xZYFtIwNTSHGwldm9HEDuYwOdsQIgAz8/61YgKJ6sDi7pvZTN8 HfrIkNH8P1/yeY2Jmcs+uxSHEI9ExhdHRo98Ja1/6KhYuaA6+h8Oz58POm25QcX6fKfi YdPebnuvVlDDZQUuJOW+x+hWvO54d5NP6YmfDUx8mls22yqoUide71LDiciyuLW4cA+c Ph7Z+pvF8WJxYO7TbAf3srZjoF1OJWhXcMur8wwq2XIsIlKnGjjt83qF6rWTKTKQH5ud WFOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZkQPYglmMf7WlOZMSJfnhEauQd7yT1YXjmkBGOPdi/8=; b=nT4sB5lOEvEIc4/mHF8Nh4PfX4h5g2XKqbZNG4nKdDiz2TGBas1uS67wRnDYEIKedU NaUGbcZRukm/tUTxkhwtdvTWxyDO0HmtXm+X5v+UT2ZgDJjt9zdDB655ubzhwKH3sOKv tHovAPpbgvEcAI0QDVz0cVyMXYvK/ob5N5hR86QOUs3Lx/XKd2Y6S5DxPMXZqCeZn8Ax 7lfPkXWnt5WCpUZQfbd3uVzDKXU/f1rb6IHVLGBUF+0i4E0Z33x7XAtgigHNLsmaI9Zp VhAjDpYxz99tbY25q78NtoFuqw0xCBEb9kVN8A6h+azwWzuv0Z08Y/eW8eHECFpjHXEI hHHQ== X-Gm-Message-State: ALQs6tDg7UyvosDgZ2dgEbaMY7iISJwklen4p+pt6WzWD28EO3rgHqId TdT5nUWeGfD4bkEyoNmytVRXt76OvXtMEe5BZdUsQCNVrd2NTSxtmDvM0s6tHMg4//5KCcBSu/m M4qaqU8iatqra9Zbwmvo1AxdA X-Received: by 10.28.158.2 with SMTP id h2mr764137wme.157.1523541348863; Thu, 12 Apr 2018 06:55:48 -0700 (PDT) X-Received: by 10.28.158.2 with SMTP id h2mr764123wme.157.1523541348645; Thu, 12 Apr 2018 06:55:48 -0700 (PDT) Received: from buildbot.pitowers.org ([2a00:2381:fdf7:14:3403:8ea9:e6c1:e3f5]) by smtp.gmail.com with ESMTPSA id m83sm3491581wma.17.2018.04.12.06.55.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Apr 2018 06:55:47 -0700 (PDT) From: Phil Elwell To: Woojung Huh , Microchip Linux Driver Support , Rob Herring , Mark Rutland , "David S. Miller" , Mauro Carvalho Chehab , Greg Kroah-Hartman , Linus Walleij , Andrew Morton , Randy Dunlap , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: Phil Elwell Subject: [PATCH 1/4] lan78xx: Read MAC address from DT if present Date: Thu, 12 Apr 2018 14:55:33 +0100 Message-Id: <1523541336-145953-2-git-send-email-phil@raspberrypi.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523541336-145953-1-git-send-email-phil@raspberrypi.org> References: <1523541336-145953-1-git-send-email-phil@raspberrypi.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-12_07:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/net/usb/lan78xx.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index 55a78eb..d2727b5 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "lan78xx.h" #define DRIVER_AUTHOR "WOOJUNG HUH " @@ -1651,34 +1652,35 @@ static void lan78xx_init_mac_address(struct lan78xx_net *dev) 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"); - } + const u8 *mac_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); + mac_addr = of_get_mac_address(dev->udev->dev.of_node); + if (mac_addr) { + /* valid address present in Device Tree */ + ether_addr_copy(addr, mac_addr); + 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); -- 2.7.4