From patchwork Thu Apr 19 16:59:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Elwell X-Patchwork-Id: 10351367 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C9DC5602B7 for ; Thu, 19 Apr 2018 17:00:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB3AC205F7 for ; Thu, 19 Apr 2018 17:00:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AFC9421327; Thu, 19 Apr 2018 17:00:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01169205F7 for ; Thu, 19 Apr 2018 17:00:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753518AbeDSRAO (ORCPT ); Thu, 19 Apr 2018 13:00:14 -0400 Received: from mx08-00252a01.pphosted.com ([91.207.212.211]:33712 "EHLO mx08-00252a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753378AbeDSRAJ (ORCPT ); Thu, 19 Apr 2018 13:00:09 -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 w3JGwthd021504 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 mx08-00252a01.pphosted.com with ESMTP id 2hdry78ytg-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 v11-v6so5882859wri.13 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=ml1mw0udcNX9KJDS0MMAJg8+GAGI/wHr5bjT+v4BHv8FYx+H00Tc4JYkGa8Zq1t0tm YlGRgye4AqNrGNxx65STKbnu3HfOz7vqHPys5m/16ifmYrWbvaVS2qFjRhe+iV8hCZPZ 6zL9Mk37zR1tifVOmku8FR82uPSpqi4JfjpY56EEFtgcft5GUm4FWdUeZnXg/8T8PlW3 6AfPsVYcwD2t/YH/fd0cPWJCLIS6xqZ1JZ+XuLamr6lqCisJlyJb/d3HBbqequ0B/h1i 2RxzAZ4lGz6ZWxLDG8HxBDbk3PJ8VoFhKD4oMODFaD0ENCDuB9xU5jBMRekkHAot9Oe1 MGKw== X-Gm-Message-State: ALQs6tB7Yak0OiQ7Mw5kpRObS79zbaa3Bcem9kpGdnViOZ8/sArbGISy b1mcnfe28sKYEzhIkYHHHtqI19qVrtkA7vo1A+PeczfNUZzbAMKCBeKXdDnTCetQ7aJpxRMHJz9 2bXXxo5bLwbXCocge089G X-Received: by 2002:adf:c301:: with SMTP id n1-v6mr5485102wrf.76.1524157208149; Thu, 19 Apr 2018 10:00:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/GmnuHRkwBEpHPNgfKSh52ydPZ4GNSMswhAhtGM8WyC9c6MEKttNlXx+ZHih/oG8zpIuUHDg== 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-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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);