Received: by 10.192.165.156 with SMTP id m28csp1381744imm; Wed, 18 Apr 2018 08:47:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx49L8qKpV44e6ihirksz7ENMM9SeB50cGyg3uQXa/BA1a/Tbbm13ND5gUJAM9BYwqsKYaGDH X-Received: by 10.99.45.70 with SMTP id t67mr2106971pgt.439.1524066478158; Wed, 18 Apr 2018 08:47:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524066478; cv=none; d=google.com; s=arc-20160816; b=aAdLZ4SHb/UtxmvaAtg3+oI86oFRsBYU5yE5T4bBeUgpQeVOXvHF1IaC6JRiGl+rth Hbrwd/V6vNMnLf6X17FooC7erfWzs1Nlwbi4oYN+KQI5GKpDHa3CPIoJAlUZABIQLIKj E82WTrRhcvMlhh7gfQQLFBh+ibtC+CS9I1WJc+iqTKVf8I9Q9NYfuzWjCFvAWCuNf3I7 E+QnnNGP+/sLu25Faa9bybKmk4vRj4m72EjEmInkGZOiJ69QzveMJNmge9x20ZTiqDg3 R1CUZRpHxAPJY2KrWxTyf6TZXxdb5rL2FuWCnn8K/ODFu+wHhSUF4pE+lU2Re4rKg6X1 UBLA== 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=Wxwk4f09DQ3bab2rD8Ijo7xdPrwQ+P5nojp4DCte8B8=; b=AYBH07QbZ7Qq2cKlXdvH7w2VX756uuFNkgtFaNHNnr1SePmtxQUnTk3SH6CRHlRAny gMGI6KijFGlSpwCwq/kBnu3bL3DUV7spvJCDQhmCTDsyL5XWO/v71+DJGGJWLexvinZv Sj5SCEYEzqJBLJRaqgRrro21Gv0tegcRpnwPrvxoaUIb9QhCWulx1wTCjjWO7RwU+S2R Fal690pYLnvJshz0kTb6lSXq6SAPYQK95SKfsJzuTLKGfMWV6uia0Rkch8NlGduI8lSE 8Q8mbl3rV9SeuA9157yImNda8yxeTpA69AS2U+JkOpeYZw+iP51CFoqZjUnlKs1CWAqf FmCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@raspberrypi.org header.s=pp header.b=PwVMtgqo; dkim=pass header.i=@raspberrypi-org.20150623.gappssmtp.com header.s=20150623 header.b=af4rytZs; 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 o11-v6si1454474plk.434.2018.04.18.08.47.43; Wed, 18 Apr 2018 08:47:58 -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=PwVMtgqo; dkim=pass header.i=@raspberrypi-org.20150623.gappssmtp.com header.s=20150623 header.b=af4rytZs; 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 S1753935AbeDRPqi (ORCPT + 99 others); Wed, 18 Apr 2018 11:46:38 -0400 Received: from mx07-00252a01.pphosted.com ([62.209.51.214]:19215 "EHLO mx07-00252a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753435AbeDRPpc (ORCPT ); Wed, 18 Apr 2018 11:45:32 -0400 Received: from pps.filterd (m0102628.ppops.net [127.0.0.1]) by mx07-00252a01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3IFYJLZ029016 for ; Wed, 18 Apr 2018 16:45:31 +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=Wxwk4f09DQ3bab2rD8Ijo7xdPrwQ+P5nojp4DCte8B8=; b=PwVMtgqoUguZtg22WnOqFsULs+SeGVFjBc4f4+uo04iDwbnqjqugFdblKobLnuwgDiEZ ScHwyAIk80FQvDk15/eOVO/CPJp0HsxGn1+4jWlqN1FF8HkHi6PeQxG77kF0Xqal0SLb rb2iEUSuqT8FtZQ4+FMEI5OqMHG9I7KKsmUgQXkh9ImaB0eRBe1rqPcLTD3UqFh13A6C wcnHF0MP1xEwWp5Ln9P9pnMM/qVoMErMu1mR/DLp2Rp8BiIzmDe5Rt07nrPnH4JBzCnG mZfTNXmOFkRmdNb3LrZ4utgH8ld8a6hkZO84m3EETv7sTTSy1TgdbV24TTmxVCFO2Tnv 6g== Received: from mail-wr0-f197.google.com (mail-wr0-f197.google.com [209.85.128.197]) by mx07-00252a01.pphosted.com with ESMTP id 2hdrya8drm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK) for ; Wed, 18 Apr 2018 16:45:31 +0100 Received: by mail-wr0-f197.google.com with SMTP id u13-v6so2230446wre.1 for ; Wed, 18 Apr 2018 08:45:31 -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=Wxwk4f09DQ3bab2rD8Ijo7xdPrwQ+P5nojp4DCte8B8=; b=af4rytZsL6jVZa3DUTNfrYQo/cY5NoSHDaNZaJX4kny3zJLLNjptzQvx2eO6UgUoAw gntuGwCBUTC6ym5Cj6fMhj8duR4iRMvP1g2PwZtgJv83yc8r0GMCTHHnNYuvfWO85u3O hEFQLVgk/tI0PHpMk5mcsR3BIUQvb4o/ybTIVXYSt2jQLm8/qIsQL2kuG3wHHZRMIN2L nhKbyJNeuFt77L0XeubhrjhHCL6DE21FOsASEhUtMt+BQHEdc5oD+lQTWOw9+5DmoQOE wLJK1Fzi6U+oRTxlo6aV884z/rXEUc/UwIhxTat7Ln8HLKXZ0y/q+6HuA76/GG1+b7R4 pzQA== 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=Wxwk4f09DQ3bab2rD8Ijo7xdPrwQ+P5nojp4DCte8B8=; b=Ixps3YVZpEGhWA+rfsTsLsfTgBAAZ8QUt2M6uB2eogJp3j3ASK8a5eTKgrsGHU0Py1 M3rycrnJZ3oSszEPy+vcE4Iy4KVh12HXWkwaQALzHTQJAWHY+tskxLCDaxj2hKAWSiUk odiZHRqC9tq+DPMfXGOaHZObaSXj6QUXJsP4w7I2/PUJppMDR3sAyFpqd8BB+Nn0UTkb hEvHKVOwr+w7Oc82Qne5tJMt9+RPTqSVkx2ZCTzRYMi4fDXBN7+lt/StMS99TbvZCC6R 6/JecRcAs6C2Vv3esEylMb/aupHo1sbheRtZYogEKcwNk4kFDChI9Tlwou/D3EVIT6l6 tmfw== X-Gm-Message-State: ALQs6tBG4miwABvoL+kAjr9pXoEzxsCsPryr9rKKOuQpTwVFPEDg3DVt U9dhSGsDutLBQe9jSS+y5C8qFM0fp81zL2YMO/X1huiyh63yGCHnfEByAVlaGBynL//SIS9h769 qTJ7K2z+ft2sEwWrIuBb8rVzU X-Received: by 10.28.235.3 with SMTP id j3mr2196200wmh.146.1524066330794; Wed, 18 Apr 2018 08:45:30 -0700 (PDT) X-Received: by 10.28.235.3 with SMTP id j3mr2196172wmh.146.1524066330423; Wed, 18 Apr 2018 08:45:30 -0700 (PDT) Received: from buildbot.pitowers.org ([2a00:2381:fdf7:14:7931:3b7a:4272:adad]) by smtp.gmail.com with ESMTPSA id n79sm2752689wmi.20.2018.04.18.08.45.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Apr 2018 08:45:29 -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 v2 1/3] lan78xx: Read MAC address from DT if present Date: Wed, 18 Apr 2018 16:45:21 +0100 Message-Id: <1524066323-109628-2-git-send-email-phil@raspberrypi.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524066323-109628-1-git-send-email-phil@raspberrypi.org> References: <1524066323-109628-1-git-send-email-phil@raspberrypi.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-18_03:,, 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 | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index 0867f72..a823f01 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 " @@ -1652,34 +1653,31 @@ 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"); - } - - 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); -- 2.7.4