Received: by 10.192.165.156 with SMTP id m28csp837708imm; Thu, 19 Apr 2018 08:20:46 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/nJUqEa+aSKY64MhsPlw4KwRhzZyaKSJJP520CI77INMJnFVs02GddSPhzcl0yQUUHSfty X-Received: by 10.101.70.200 with SMTP id n8mr3923613pgr.62.1524151246403; Thu, 19 Apr 2018 08:20:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524151246; cv=none; d=google.com; s=arc-20160816; b=DlB67z1wNoD1s8h2W+0vwb8YiaJlxdA6OJCZm61qAl+fvVktFt0liCuIyl7O492/G7 uAK/y2XhUb+sFDkk1DaEETBoMI3LDMbw4TUgk6lPDe4qdWKYbub89HMbQWoQVOZrWWKW 7jUQDStLWmubJrG8cvuuhJzfnfF9YN1kglYC97441ynoz+yzONvw7pLcuq9OhgyomvKd ST58uzFEfpe0+x1jGcjnAu1uGB8X3vnHcjgVEmDKlAVB7YhTXLU5b3omHq+oZLnJqI5S eWw264hnXlMZOaKzV57DHCx25l8Qz35v1PS+KS8iibMSliE5vlUISTDT0qTdWn07zpWQ Hl6w== 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=OPygOowu25CMYZJFRmjsbQTL7aIbdMvGriXBi4JxanHUiyeiVcFaVSFysu7KyozKVz 6uYdLs/V4t76RQtZz4FRCB3W3npSi25qMs75OXUBTkKKRaUaTnUQuRcglQJUD0R4dJ1R Jl7lfX7IcbT/771UPUqcgb7zcwdU7t6PZOfxU39w3FPVPQrZYlSy6keSAyfdp9SyqsAI sidR/r7b5parhGomtLHVDv+P05OloPOT2xDLnNGSrSdZKbDPAJR9c4djGp29584esc0j 0Sls3M1adBpC7e9hebDHya/TXKmsY3aqO4Dyj0yzV/hac13BHQ+smbqwxvyKnSNZnTJJ irHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@raspberrypi.org header.s=pp header.b=C5kJgj1C; dkim=pass header.i=@raspberrypi-org.20150623.gappssmtp.com header.s=20150623 header.b=y9KINavL; 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 p85si3435973pfk.77.2018.04.19.08.20.32; Thu, 19 Apr 2018 08:20:46 -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=C5kJgj1C; dkim=pass header.i=@raspberrypi-org.20150623.gappssmtp.com header.s=20150623 header.b=y9KINavL; 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 S1753110AbeDSPSK (ORCPT + 99 others); Thu, 19 Apr 2018 11:18:10 -0400 Received: from mx08-00252a01.pphosted.com ([91.207.212.211]:56650 "EHLO mx08-00252a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752337AbeDSPSD (ORCPT ); Thu, 19 Apr 2018 11:18:03 -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 w3JFDORd020600 for ; Thu, 19 Apr 2018 16:18:02 +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=C5kJgj1CaEhsPB0bN2N0a3CVhfRXVUMXMlB5eNW2EgRFUsMzrj7IFKreWG2BYpoqc3Cj D2Pbj12U21eYuWama9JflZRrWZe7InrUlw5KKmuodA620XNkEj2o6e/3304GQXLXbLbm 5FDXtSh85gZnFCz9aHoeZy9Jpan59PWpK7ijv3CpZtT/9VCGYw5C+YSJXFf/NadA6tP2 2hvry5TOBu0hoJO6RrIVeGDj/vji7nO/LanEWTBsLcHBjCJot1YnaIayi+gG6q2f4XsQ vGuWGJYzNHI7v5IrPSbL1CW1a2zcOK8pf9HGjqqFdpsvBfejJPzGAsoKfXGh7UeL+7IV Qw== Received: from mail-wr0-f199.google.com (mail-wr0-f199.google.com [209.85.128.199]) by mx08-00252a01.pphosted.com with ESMTP id 2hdry78xgf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK) for ; Thu, 19 Apr 2018 16:18:02 +0100 Received: by mail-wr0-f199.google.com with SMTP id y10-v6so5611793wrg.9 for ; Thu, 19 Apr 2018 08:18:02 -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=y9KINavL2ibknMBJpwxDLx6rx7wLUPJGAv5yX6xH9MNUYey/enASMhAPknhM1scSEj K14xd6RnTltNLJ8BZX/wS6dkY5MB4rKJWRv9YTdfRSnxT8mdhF4Era638jTb+7CpXKI8 1gtwUwwe5zIX209WRcq7nJj2LUtf1NiABPnEAL+W8kZ8X8VIkWE/Gxfz7lZCAFvB8gVe uESdtt/KlvieuZlxOe3U0xEJ960Y08is3pFM3hesO1M78YonLubXdA1CbA7JQe5D8zz0 GmYyWenOCqBN46g0iIKswKCstnAnEz33XHoXE88NDSYa689yFjmUvPod1cOaidT19Krq eTXQ== 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=TrYeZJIm56QqgTkCkf+G8yVJ+rbAGBZItQCPS01zcg7Gzt7iH5S5VZ68EggaV2axak EWJ0cjHURewiGFQSV5qQEnqEJB0twMEQtEUh71gGNybSgiXEBUZD/jsayZdAaugaPLZO 7ikTFzzlwBP1R2irj+IYpu7XO8bU5L4aqCRja5c4njqhKRYo7SCer1/Bjx/mtNIkdnbs SvUr2scX6pdHzgWFSPZlZZhKkS17GX4X3WPJamczS/3JO2xZpmidZouLca4eq2R9857p CfMNfd2akouzwVyi3PHvIRs5LmUuzT9Dd4K1pwo0DZHCec5olX8BpE6qTYbzrixQMMZF uOqg== X-Gm-Message-State: ALQs6tCeGpf8obKJR7uKgEhTBJX5rAWoislfD/pCviCB3a//3Ezyy/09 tycdpbSIqENgMyA6h4L/oJ1BxWAIciiQ1lo4za45YcL4RyhwSv1kXv/j35fk3SlUcFLR8YfuJVM mNjNtZUTuFIqfuhixBZGxAAUF X-Received: by 10.28.155.206 with SMTP id d197mr5080077wme.44.1524151081872; Thu, 19 Apr 2018 08:18:01 -0700 (PDT) X-Received: by 10.28.155.206 with SMTP id d197mr5080065wme.44.1524151081645; Thu, 19 Apr 2018 08:18:01 -0700 (PDT) Received: from buildbot.pitowers.org ([2a00:2381:fdf7:14:3509:880e:14cc:3c11]) by smtp.gmail.com with ESMTPSA id f15-v6sm4322342wrh.35.2018.04.19.08.18.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Apr 2018 08:18:00 -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 resend v3 1/3] lan78xx: Read MAC address from DT if present Date: Thu, 19 Apr 2018 16:16:57 +0100 Message-Id: <1524151019-82823-2-git-send-email-phil@raspberrypi.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524151019-82823-1-git-send-email-phil@raspberrypi.org> References: <1524151019-82823-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