From patchwork Wed Apr 18 15:45:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Elwell X-Patchwork-Id: 10348587 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 0A86560365 for ; Wed, 18 Apr 2018 15:46:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEA54286F9 for ; Wed, 18 Apr 2018 15:46:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E28E728705; Wed, 18 Apr 2018 15:46:39 +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 350AA286F9 for ; Wed, 18 Apr 2018 15:46:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753331AbeDRPqg (ORCPT ); Wed, 18 Apr 2018 11:46:36 -0400 Received: from mx07-00252a01.pphosted.com ([62.209.51.214]:18970 "EHLO mx07-00252a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753296AbeDRPpc (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 w3IFYJLW029016 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-f199.google.com (mail-wr0-f199.google.com [209.85.128.199]) by mx07-00252a01.pphosted.com with ESMTP id 2hdrya8drf-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-f199.google.com with SMTP id k27-v6so2134701wre.23 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=KHD0b8+7KOlNGWrocQhI3SX1eSf7Hj5kjjTBbDe85OvdE5ZFiUzQtxLjpMFfXJ15Ul UoqZgbggHtT5JWuqRTr/bukh+mMwdoSXMabcrK2pC5URU2CUSDtPnflVMUW1+y6QU0VJ sAdhMw4iMlECalH6hDeKbV0boUWfoMuo7STT7rwzQtOSRbhisgTAet5jJfnOWXEilnld KA/DoCwnMpzYNV+0l3WFWB0f1PmA4AyXKPjFbVYPiXErndGrLb36lIesLqnpGyxIgR7c od68yDGXfb65N/Y67YWTJfhgF/JXb1LXOsNg3+G/m+4om2yDPoAzBuUtT2VH0fgrY0sB tbSQ== X-Gm-Message-State: ALQs6tBQAHIWn69aE7j6dHnK77SsCyLOGUM86rYyatUoZ1L1h/23yxb9 5sAkSbZd8mQbX3xH2lCGZapO75HPgLlEJezmQQNPoT4aN5gi3VjVp38cKrd4GCKUkviygepAf1R qB5Wjq2tjalV+E2AhmgUI X-Received: by 10.28.235.3 with SMTP id j3mr2196199wmh.146.1524066330789; Wed, 18 Apr 2018 08:45:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx4951zmk3Fm6Ea5OfpmMQXQjYV45XZhMoVWI8QNxAE7V++WRXq3WpU/kiBbHQtnpgRnvfUtDfg== 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-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);