Received: by 10.192.165.156 with SMTP id m28csp944316imm; Thu, 19 Apr 2018 10:03:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/814RZnA0JAz3R+b1Mst1/4xR0kqlD01H/H/dx76FBSM+wGxIbJRhFJTxIEjn6UdIggsMp X-Received: by 10.99.123.15 with SMTP id w15mr5569196pgc.405.1524157427521; Thu, 19 Apr 2018 10:03:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524157427; cv=none; d=google.com; s=arc-20160816; b=FojkWo4Kf3oLpRmDnR+AbmI61GMsz+0ikn96WiGeONFhTg7bDqfRiBoKprSVxKW4Gz /N2NGR8JFjanJjMyuXvJgaii7W26D8PiwFr+Bw8p3JaPvV++6TM58MtMeR7c5kaVuSd6 y/VUXMGuLOfbCjISqsjFmNFPDLtRkuJKk/feOZ36LCHB4ZWFh6XbHs/lW+ARHkrXliIs d8+mo0jm4cVJjP19xRuVeg+54V2DJb3+hIxssSWc71gKdia/8HILhNZyAdj10uXEpAnY anr7PCuc0/vt0VIfrMRcxci/Z3Whq+KLaxDsJnMiFFy15Lq8vEMsxQHLeoDZ66RjxlQz 1ElA== 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:to:from:dkim-signature:dkim-signature :arc-authentication-results; bh=Wxwk4f09DQ3bab2rD8Ijo7xdPrwQ+P5nojp4DCte8B8=; b=ph5nV8SAfxYpFD7oV4NICgCC/qEh3tREyFaySBcOlx+nPoxadfrSOOSYI9poQulbBm GKnmFjEFfQQmFJmpekA60sErwpYl0GZY+QvL0aC9B49PMdBnr/UCJ5/CuoZD4isfu0Qz cbvcNHI90yy9T2JXGmLLc7PFp7+k9bGEM2NVqk8KrYoGVj5B+dT8vbgg8iIdPCTvTZx4 xwnsmd2PzjN4QnukkoX0yLRZMQBUTyacx5X0Y3aoUg6MKPIdf03RX+HIhNp2yBfY5wOa 8rtBTf1iI0yhpJ2IJgIYIILKEnbAxj0t2Es0VgBI9u30a52SQLzb+dEQ2E08em3QOx0c KEAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@raspberrypi.org header.s=pp header.b=3iIP168C; dkim=pass header.i=@raspberrypi-org.20150623.gappssmtp.com header.s=20150623 header.b=SaAXWVmY; 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 n23si3188168pgc.359.2018.04.19.10.03.30; Thu, 19 Apr 2018 10:03:47 -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=3iIP168C; dkim=pass header.i=@raspberrypi-org.20150623.gappssmtp.com header.s=20150623 header.b=SaAXWVmY; 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 S1753537AbeDSRAP (ORCPT + 99 others); Thu, 19 Apr 2018 13:00:15 -0400 Received: from mx07-00252a01.pphosted.com ([62.209.51.214]:28485 "EHLO mx07-00252a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753386AbeDSRAJ (ORCPT ); Thu, 19 Apr 2018 13:00:09 -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 w3JGxj4t012438 for ; Thu, 19 Apr 2018 18:00:08 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.org; h=from : to : subject : date : message-id : in-reply-to : references; s=pp; bh=Wxwk4f09DQ3bab2rD8Ijo7xdPrwQ+P5nojp4DCte8B8=; b=3iIP168CMBfEGTyPAYuD4WMez2nDFc20JcMToiN3NnuP8thPjqK131W1Wx9RryxU3JcX 5+44rd5pJvCBpmTrLRjJPLfY8vpZm1F1VUIb9wbI+Xk3b6oKf4E6Nxj5C0kZpWbQJU13 vQ0xb8wETTlhqpGyPw1QAV11OiXb6cj2SFNPjbRASFMrx/eFXOiQrwis+3wxJZ3KwfYQ Eyng4m7Ie9pOX6hVGHlePBq6c2zq4B8WfXC0otzrP8E2uESmp2nrJYZffr8fXc9hccg6 uxw7wrtAUfKbvswjs46i1yjcafawC/TGmB3llveLdsM5ojKUrhvs3y3SuxhdPq9os1zD uA== Received: from mail-wr0-f197.google.com (mail-wr0-f197.google.com [209.85.128.197]) by mx07-00252a01.pphosted.com with ESMTP id 2hdrya9007-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK) for ; Thu, 19 Apr 2018 18:00:08 +0100 Received: by mail-wr0-f197.google.com with SMTP id 47-v6so5886892wru.19 for ; Thu, 19 Apr 2018 10:00:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi-org.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=Wxwk4f09DQ3bab2rD8Ijo7xdPrwQ+P5nojp4DCte8B8=; b=SaAXWVmYP88yVYvnbQAVWiZOtaoc0aNLx4Frh85Kc0BUWISU2lxoM0Rzgf2ZWgk1/k HG5gTDTQ9wZCh8Ox6l4FEOwOt48tB7CXj3jAPLTzdtH6GhcU8rO6I7ykjP4Oi8c5R8l8 R6EgX3C6A0bsQHJa2wZHjzlwHDy5qiuxHOVdBQ3Bs86jWDw4BbjXfEkWPD5kPWOs5bA4 4B4GwTV+wBjAGTbgxQUDRJV3IWDKA4G6JK5gyTAhEeFwhwrG8fGejsmxupjz6/QLjckQ UvGi95V8997/3UIHdGcKF/+mHQxZRQ9UL3VtNoUOeAG/RwNYbqgIdx64FPqdL/1YhSfB dC/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Wxwk4f09DQ3bab2rD8Ijo7xdPrwQ+P5nojp4DCte8B8=; b=RuHE49/z/I7rTTqDgKya561prUvkBNXJbl49+O+OBLegyV3FYr/UPV7WlnZErFB3j3 t1vGX/DKsMyPi8+e26DwsC7mP+kJXOHqiXxc8JoCMS9WIaddjTspRQ2+df4iQw9DDEhh JChJFh9BPMKUCa4azmsxd0mRDzK+icvw+FQiB5av6gaz4c06sgHv9kc0yeVP1M4CKn4/ KcDFonqiCNj/tWKlsmsTb9w9Zh8kx3vowDxd+hHTyvnwZYO322Lne3gX0Rid9OPbVQ7e HaBS8sAHHbBzzEw46DO5xo9RIvR7X8CUo6LbrXlRECDmtO9fNs+eF842C++0PSp3dyt9 O64Q== X-Gm-Message-State: ALQs6tD2OglJzDwIK55NYkea850NxLOQYv/x/vrPGtUNkm2c7LG3MkEl QWjzuYVzeZMr8D1I5+lO0rsRgHwlxdqquEb1OqAEFdr6BXwZLwiykdMIxPNvY5+TG9dti1mEO+k 80mydGWIfHLiKAz3UiKV/iYuB X-Received: by 2002:adf:c301:: with SMTP id n1-v6mr5485108wrf.76.1524157208152; Thu, 19 Apr 2018 10:00:08 -0700 (PDT) X-Received: by 2002:adf:c301:: with SMTP id n1-v6mr5485090wrf.76.1524157207949; Thu, 19 Apr 2018 10:00:07 -0700 (PDT) Received: from buildbot.pitowers.org ([2a00:2381:fdf7:14:3509:880e:14cc:3c11]) by smtp.gmail.com with ESMTPSA id a139sm5581532wma.43.2018.04.19.10.00.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Apr 2018 10:00:07 -0700 (PDT) From: Phil Elwell To: Woojung Huh , Microchip Linux Driver Support , Rob Herring , Mark Rutland , Andrew Lunn , Florian Fainelli , "David S. Miller" , Mauro Carvalho Chehab , Greg Kroah-Hartman , Linus Walleij , Andrew Morton , Randy Dunlap , Phil Elwell , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v4 1/3] lan78xx: Read MAC address from DT if present Date: Thu, 19 Apr 2018 17:59:38 +0100 Message-Id: <1524157180-27276-2-git-send-email-phil@raspberrypi.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524157180-27276-1-git-send-email-phil@raspberrypi.org> References: <1524157180-27276-1-git-send-email-phil@raspberrypi.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-19_05:,, 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