Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2550022imu; Thu, 29 Nov 2018 06:45:30 -0800 (PST) X-Google-Smtp-Source: AFSGD/VVMkZsbvHO1D9KmWr9HizvJ2J3OJuca9KjuA7TjVjzMKOC6RVQn7qMm5Nqzoih3PkygMGJ X-Received: by 2002:a62:5950:: with SMTP id n77mr1641269pfb.128.1543502730369; Thu, 29 Nov 2018 06:45:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543502730; cv=none; d=google.com; s=arc-20160816; b=RU60Nyib1hX1SNWb00d+5n/J2KT7f6WUV8b30ppzR1X6VCPaCGqvFraf5cSqrg6yGa 5P75odfWYb5Yk6dYncyEJJruTCri8DA9HVSzNEQHFH9WUcK4fbKr42yQ2gOHBoisoqvn ji1LuNP/YyfmibKxQwX8MFRvZ9A5gyxldb/gU2OK6bdDrsN3KZDdJMOv3ukQjvjGhlQF hqTp/GJHGPrLixkvQleQYMHigEYEFvvheZCwophKYWqA7Lk59ABqPXqBW7BgmQ5jCd8X Lc07S2cA8c9yft84BFltpvvBpfRx/Kjlfa7Q3WyMy9ZxEGttLGKwN3Fg1Eegk1m+2MUm leTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iv1UQQ74OoljHX8MKxqJqhCbdmlI092PNtdeMJo6/Ec=; b=pYchg20bMEtEFsL2STOhKgtp032XQKbSDfXfya6RSELZIzZ0vrzBpn6zGEKjtp+c4w zZv+2S3L4ia763XdCQ5A43I3knVmx11NSbX/eS7AZCLjgLSFR+wDKyErCNo+fAlax8N7 3xlkGeddk2kb/AO9qAAAdU9VDDM/rzjp38jmsMvm/kxUba2zieFd2jN148547FgJQtEM BRbAv4/CGilACDdwk2fWFsmIfKhmcDirYyibVikvj65ysHNHoub+ZZmc6k++h+rrqSLQ O9E9IvlJFsXDqLrVmv+1RNPD0tp730cJnKgwCDOq3J56kk/UhfFaYjSvLFYjzCGgnKVy 2X3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XbMcfivf; 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 c1si2417007pld.194.2018.11.29.06.45.14; Thu, 29 Nov 2018 06:45:30 -0800 (PST) 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=pass header.i=@kernel.org header.s=default header.b=XbMcfivf; 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 S2387845AbeK3BdW (ORCPT + 99 others); Thu, 29 Nov 2018 20:33:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:33928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728759AbeK3BdV (ORCPT ); Thu, 29 Nov 2018 20:33:21 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 869F02133F; Thu, 29 Nov 2018 14:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501669; bh=4na5yxT47KF4ZUJVEzsY0WK1bao8i5ds/MZr3HanBJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XbMcfivfn8DHYsRTqjRa2nx57umL2xJM0fEDUyOvUipmLOz0jH0d93o1MIPuOY2LF nk8i+Wt8gZA8FMtx8lOhncDUFudn5/DSBwVczNEQSoQyfBycudASpCRYvhJq17KL8g YEnpR6b7s+5YvLcHUM9iP8GBeS9Xeu0sUUkPL4lY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Phil Elwell , "David S. Miller" , Paolo Pisati Subject: [PATCH 4.14 093/100] lan78xx: Read MAC address from DT if present Date: Thu, 29 Nov 2018 15:13:03 +0100 Message-Id: <20181129140106.799801664@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140058.768942700@linuxfoundation.org> References: <20181129140058.768942700@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Phil Elwell commit 760db29bdc97b73ff60b091315ad787b1deb5cf5 upstream. 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 Signed-off-by: David S. Miller Tested-by: Paolo Pisati Signed-off-by: Greg Kroah-Hartman --- drivers/net/usb/lan78xx.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) --- 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 " @@ -1645,34 +1646,31 @@ static void lan78xx_init_mac_address(str 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);