Received: by 10.192.165.156 with SMTP id m28csp788511imm; Thu, 19 Apr 2018 07:35:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx49NbSJD/Txmz/DPSSHRBESdegu1SRlT2bTSianbufkie78IbnPMgVyyaWMx9FE2TCVP/Amp X-Received: by 10.98.180.2 with SMTP id h2mr6039372pfn.189.1524148523543; Thu, 19 Apr 2018 07:35:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524148523; cv=none; d=google.com; s=arc-20160816; b=DWJAi3uNRQ6vWQIM4GGuFAFuGCrPEWP/Xj06Py8A7Ntq3yGR0gND8N54COiZis6kEd yiUkBfGK8usgvbQZXIb7WNoe2rbqLEpyT5EIIN1Q/wCVoodvPBKEUF4FBVs2SOV/Lb3j YYFQ9tUm8qL5vn/AGE0GloR4pQUQW3pRnROekG5s04CZvdApVkonWJy6AkKgOSyjvlAU OWUMNR/FOYDzeug5kJ+T6ImXIro3gkHZ2x3hT1Cn9d6tKzaa4dzMjVhlOYVBTb2TnvZG +UOnfy73jKnlUDFu0wqWKhPBMfpWIsQXK59dZ7ez9XuNv8wLSJXq0Ytwvx3ojRZuJwI0 kRzg== 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:cc:to:from:dkim-signature:dkim-signature :arc-authentication-results; bh=Wxwk4f09DQ3bab2rD8Ijo7xdPrwQ+P5nojp4DCte8B8=; b=xNX9MEHQ43kAIY/pyh2EBWZzgrJYM3P09XH0asfVLmpDOP+nGoM8SYUiMW8hDW4aQp ygXzLmBPLBalICU7+gRTiIcY7rqHFHuObhzY+BOBiHnRFQrgZB4sxwB5lvtDMF8yF9ZZ C9/WXoeUjxT28LVKsWlL2aBW8hxdt6NdsnI5BOC0SGQ2zCLoqxUJlcEshwWo9s3mAdfV yDSXX5cthlv/dZry12o7BKa8eYTokxLrqc7bjBltgHZnvbOI14+N0OkllF9dGA1fapXU 1PpUKcVkMVYyhMytJygNrktN6EzAHqGeSAA6jNImEMQG/x/Q+boYXM8225+6TYAboPe2 wc4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@raspberrypi.org header.s=pp header.b=QWiLp5AJ; dkim=pass header.i=@raspberrypi-org.20150623.gappssmtp.com header.s=20150623 header.b=d7kRaVa/; 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 p12-v6si3755182plr.131.2018.04.19.07.35.09; Thu, 19 Apr 2018 07:35:23 -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=QWiLp5AJ; dkim=pass header.i=@raspberrypi-org.20150623.gappssmtp.com header.s=20150623 header.b=d7kRaVa/; 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 S1753414AbeDSOdt (ORCPT + 99 others); Thu, 19 Apr 2018 10:33:49 -0400 Received: from mx07-00252a01.pphosted.com ([62.209.51.214]:41811 "EHLO mx07-00252a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752414AbeDSOcV (ORCPT ); Thu, 19 Apr 2018 10:32:21 -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 w3JEN1c1012856 for ; Thu, 19 Apr 2018 15:32:20 +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=QWiLp5AJowSFk9kZ+lyRC6kDEQVEeekD4/GufNLo8msiFq2YyB5M3fVsqHyALyK+4QSA /K1TY4wNq7SRwzv1aQTnt3uUgW3Enzjwh4l7a7xoIZgUObwXQeRCPepvNSNAbIkyiaKJ 84ikhIe1mrpL/JS8yZe69WgfFhvl6tchvOjMkMJV8b7jyuS3v2A/bes1npXukRb6Kn1Z +N+DlxeA/Vgb8L+ZTSBs0hXL5nf9KE8t7M3+Exn6NLMq7uEh2m5xke3avLah5up7D+yO Nw3D0i3lqnkUAP7cRatnvhxGlm2/TfbhDVF6M9+zBIlN/MzE46p4wRLVnR0C5Ni9DX4z BA== Received: from mail-wr0-f198.google.com (mail-wr0-f198.google.com [209.85.128.198]) by mx07-00252a01.pphosted.com with ESMTP id 2hdrya8ww9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK) for ; Thu, 19 Apr 2018 15:32:19 +0100 Received: by mail-wr0-f198.google.com with SMTP id 31-v6so5451526wrr.2 for ; Thu, 19 Apr 2018 07:32:19 -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=d7kRaVa/2cuulSLNtdsZDwgIEmQJpQjGEoMNKbcezw83ysmF0oIrUAo7JTlwCX/djC B+IX3FDEJsw/tOXSXem2lPIdV7n6xHX9KkUHPF/A0GSTMgbGPQ6uftSQUFGTjlmvIhg8 LN8xLLrcBlu4cajPgMp/n1698uiLpLsQoyzenz21JGxBZHDZj/kk3HzNwgiehKdBcV4d PRvu2wPmCV1ABM8QQFCkz2gYR+GZo/IUTRW48ScEz50BQsX/8PFjSXCLcNuJlHuuJmtS 33aOzdv8x+JtisMrW45Hey3CxX3J9U298Q8uuRB8/sbFATt1fCefC08VrFobfvT3k5ua 07FQ== 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=i+r0bAlM1UsCaAnqGQ7/cI8YKRsXBLcMbQPqAUUmr+HIS3+e7rUQwSRlhRepmBJc/U f3pRjMLOKS8KGrLNULESvLwv8HFWgiNleo5yTEagMUGe9UHVugcdDXcWWaj3SXE/3ZG3 D5biWVCJrm7eMlmc7n7SaVju5cGOzQpyfeV2rW1ZsHFr+RZ8hlfxQZ69JLFcqxxEoSSo 0KbJGVHPCFRQDJuXY/nPp7PKivqCrMn+4+afbEkoafb/aNNbT0gDbSgbOQp0j5Z0Ry3m ZAIpBD5chzXSn4oopWaRRBHqp8y1YjPEz72WSsBJb1F7lMHKLf70ksH2HJEZCbb59LAg 1NgQ== X-Gm-Message-State: ALQs6tD3Vu+mr7ubcPJk7BCY2OwzXZzPBFSJ1vQqVJN5zvQScy7fhXVO YH7epRikCntJrr5vpqjjGq/YE+lTH2M7OZ65JGd8ELx2LXMoptlrkDQPeiQETGdAiIFeT4WZCeY jq0HpdqN3KHRX5kI9PpAQ/d3K X-Received: by 10.28.12.141 with SMTP id 135mr4471641wmm.99.1524148339444; Thu, 19 Apr 2018 07:32:19 -0700 (PDT) X-Received: by 10.28.12.141 with SMTP id 135mr4471615wmm.99.1524148339207; Thu, 19 Apr 2018 07:32:19 -0700 (PDT) Received: from buildbot.pitowers.org ([2a00:2381:fdf7:14:3509:880e:14cc:3c11]) by smtp.gmail.com with ESMTPSA id i44-v6sm3465473wri.17.2018.04.19.07.32.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Apr 2018 07:32:18 -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 v3 1/3] lan78xx: Read MAC address from DT if present Date: Thu, 19 Apr 2018 15:32:03 +0100 Message-Id: <1524148325-78945-3-git-send-email-phil@raspberrypi.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524148325-78945-1-git-send-email-phil@raspberrypi.org> References: <1524148325-78945-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