Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3004319imm; Fri, 10 Aug 2018 02:00:47 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxiLZdMEeJ2GxjWM+1S6C9GO77P+mUv3BucJLMhXw2DvgPSh2PzT0UjwbwT3e01jAJLYS4R X-Received: by 2002:a62:4808:: with SMTP id v8-v6mr6192270pfa.89.1533891647363; Fri, 10 Aug 2018 02:00:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533891647; cv=none; d=google.com; s=arc-20160816; b=OSXRmYFERtHm2ltXTX1Kd6BmAVcALqlMgCoCgR9oJYFq1bSbPqY0+SG2wueOdJEqQV SwBo9VYRuoSd3uoi554NTWfv47U713H3cW5tRX7bJu401GD2KlynWGxaH4LD69c9c3TO w9DBU0gNwbvuWZMDNBvbZA7WEbXCHUGY4T4+4llv6vmyOpNmDJ5uq/KJE7r2lgQg9pmn Bqn691sQY6R5zaw9DqQh+eO9m1L0Qabafle125RmWjLT8zJdiaBaS6S2J/hk4nf6KnxM vDZXWYZ/ZrszM4Yrfm2y+sXIqzM8/8liiloWAWsvO++lqJRI299IYDza71dSiVAHWivv qB4Q== 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:arc-authentication-results; bh=xBCyNbNCPITfm/FYEaMd+IK4mUMo7ZN7E7Ko6Q08LvM=; b=EKvd6SSyAMMWyAuHKlVGVzAJowybLh/31pqKMTx6KrNXaaKjs2Td6Bj4OhEbNDwa3U eHJCeioMLvsk40bE9IXzwdoXHEPjlmrWsnXsVVv7cvxfLmCr+t3GSBktaMAqIREa74MX ddg45MeNwTr98tp9P1K4S8kZlqj+koum3xnvaK+QAXQLdleelIpgvuxVF8Bbt7gwY3w3 k9unpE5S9k3e1RQLW5H9nwatVIZCfp0AvtgWJ1HGmkSaNaArB2FV5gEHeTFSES0QM0Ns /HWx9tWHPmm/jGGXM4TBlCoPwQ8Ixh0WQOJ0iJihmMAWmbtSWfDAI93DyIUMKI8H5rx4 M0/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=ZoSD+iUv; 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 192-v6si10602583pfa.81.2018.08.10.02.00.32; Fri, 10 Aug 2018 02:00:47 -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=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=ZoSD+iUv; 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 S1728340AbeHJKeu (ORCPT + 99 others); Fri, 10 Aug 2018 06:34:50 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36557 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728303AbeHJKes (ORCPT ); Fri, 10 Aug 2018 06:34:48 -0400 Received: by mail-wm0-f66.google.com with SMTP id w24-v6so937812wmc.1 for ; Fri, 10 Aug 2018 01:06:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xBCyNbNCPITfm/FYEaMd+IK4mUMo7ZN7E7Ko6Q08LvM=; b=ZoSD+iUvQYCrkYLzuxLovIKe7P6g1SzIAaKg1KbZIqH8t+2kAOF4XKmk+NS1KXP6vF cPNFZ3Sc5sxKFR7uxTY7nwe7P4/pvzM2LPPB/0tX4nDr18PB5QsFaLhTOfVd4kwty3rk p6PtvVnld4i7zINBC1jaxatDY0l7Tyrk9U8neYeEVBxVpX5T3YlzC6n/X2/c0uUYyviZ LRNQz26ewZJW/BuDz2Fxfkmy/IeqdITTUyn9x3U4Ul+cME/zYMWcgBuo+2+ksEKtrYfo k/nn30kdsam5V6Gte4JXQF60uB1EMrbabLMexof3N8qTZ4NWJxA//9s1o5oordEMLuwd Ar+w== 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=xBCyNbNCPITfm/FYEaMd+IK4mUMo7ZN7E7Ko6Q08LvM=; b=cHltGCKq1OHSTe4sZD+uCmUhrFjp+dXe91sj8w9kHRs9Z93d9LfCnhrgoQQfydy7gP W4z3+1elhcl83nKarKsNlChzu6js5Zr9TMWMl1VIx+ltQpjjMPA4w3xi6IbrlYrEeJSk 2NGxBOWJjINSmBXTZBK8afrpkgKWN1KREFu4idct0AFn0zqjopU6ejN3I6yynd9VZlym HWCRPJxgRHDUH73jT+IAau+dTPxBttCRDEDSYdgcBPXYUhTgUIkOIs7tQXMXIeqKdiAQ 9qa6OoOykAR6HZ69OA16363DgB08GYoO8isM1EQLZ7C+BKGBRlOZ3UXnnKDcFXAcj+5k 25+g== X-Gm-Message-State: AOUpUlEiWno8PXrwqx2/YVLP3WLi/hd7odx1dn34T4KTxysmQjywgUy8 qHmBArNsse2n9QhMH170jvLDDQ== X-Received: by 2002:a1c:5bc7:: with SMTP id p190-v6mr775080wmb.101.1533888363093; Fri, 10 Aug 2018 01:06:03 -0700 (PDT) Received: from brgl-bgdev.lan (LFbn-MAR-1-609-89.w90-118.abo.wanadoo.fr. [90.118.185.89]) by smtp.gmail.com with ESMTPSA id h7-v6sm9546405wrs.8.2018.08.10.01.06.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Aug 2018 01:06:02 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Corbet , Sekhar Nori , Kevin Hilman , Russell King , Arnd Bergmann , Greg Kroah-Hartman , David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Grygorii Strashko , "David S . Miller" , Srinivas Kandagatla , Naren , Mauro Carvalho Chehab , Andrew Morton , Lukas Wunner , Dan Carpenter , Florian Fainelli , Ivan Khoronzhuk , Sven Van Asbroeck , Paolo Abeni , Alban Bedel , Rob Herring , David Lechner , Andrew Lunn Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, linux-mtd@lists.infradead.org, linux-omap@vger.kernel.org, netdev@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 16/29] net: add support for nvmem to eth_platform_get_mac_address() Date: Fri, 10 Aug 2018 10:05:13 +0200 Message-Id: <20180810080526.27207-17-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180810080526.27207-1-brgl@bgdev.pl> References: <20180810080526.27207-1-brgl@bgdev.pl> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski Many non-DT platforms read the MAC address from EEPROM. Usually it's either done with callbacks defined in board files or from SoC-specific ethernet drivers. In order to generalize this, try to read the MAC from nvmem in eth_platform_get_mac_address() using a standard lookup name: "mac-address". Signed-off-by: Bartosz Golaszewski --- net/ethernet/eth.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index d01dd55de037..f6f6af05fb58 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -557,6 +558,39 @@ static int mac_address_from_arch(u8 *mac_addr) return 0; } +static int mac_address_from_nvmem(struct device *dev, u8 *mac_addr) +{ + const unsigned char *addr; + struct nvmem_cell *cell; + size_t alen; + int rv = 0; + + cell = nvmem_cell_get(dev, "mac-address"); + if (IS_ERR(cell)) + return PTR_ERR(cell); + + addr = nvmem_cell_read(cell, &alen); + if (IS_ERR(addr)) { + rv = PTR_ERR(addr); + goto put_nvmem; + } + + if (alen != ETH_ALEN || !is_valid_ether_addr(addr)) { + rv = -ENODEV; + goto free_addr; + } + + ether_addr_copy(mac_addr, addr); + +free_addr: + kfree(addr); + +put_nvmem: + nvmem_cell_put(cell); + + return rv; +} + int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) { int rv; @@ -569,6 +603,10 @@ int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) if (!rv) return 0; + rv = mac_address_from_nvmem(dev, mac_addr); + if (!rv) + return 0; + return -ENODEV; } EXPORT_SYMBOL(eth_platform_get_mac_address); -- 2.18.0