Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp969746imm; Wed, 8 Aug 2018 08:37:52 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyur2e6sLriyikX7jLJ1dSJmnEToVzOCSf+jYBl4gx2/4kp+WWvSUuPN4AnR6aLi/D8E5it X-Received: by 2002:a63:a5c:: with SMTP id z28-v6mr3011684pgk.209.1533742672455; Wed, 08 Aug 2018 08:37:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533742672; cv=none; d=google.com; s=arc-20160816; b=PbaUJLXFSFEv+erXPGiLo2UcsRhUWLJbXDvhHfKJg158jDue9ZzcG8W4Usks/5KWMh SRDFapNYgeeIbPQqG4H1cvNLoktDgVAxh9vobanz6iL9TFv79bo+9Gc5UKO534gQ3QUh fUgxfy6KCw5mh8lFPto+5Ghe5mNJuEprm67uuhzJ212XQ6dZuCMcQE4WdSE6ed8+yqrg EO76eO8hUhRq1DmyGiAElbRZ6oxb+MlCYFfDMIM4gl9EJb9S5RYAouqXpSdTAZJOYIUH VT6PUFHnPkej0gFbNYJgI90QKo6jOqE0uTNNqd0Hysr3mqoi4V3qxORKAMdfZ6CW6NZM Fwsg== 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=0gvZONlvYfavZIv9YJMRdLBNbGF8vyYhSH/TZ/EBwZA=; b=DHEsrq4tOr+y0SUAt72Z3tetYQuuP3fZB1yJTqubW3/dWu360HiaTpTqCGqV+DKc3v OUONgeRJ2S0WsH/68EOlUbnBeSLy4+dbsnFvF/bFxlMTjTStMlkFBK+zGo56EEI5XY9D PAuxl1gYnM4TeOecZ+IGV0Td2ZbOus9wAonNHyrPX+51WIxbasR1Pby8+HUWELN3Qxsc wxbjZEeLd1j07rAfCkGckPKhmDfKnwxnELm1DTFSKbcer8sWavflNy4hYyhMJQKfxl48 MEzsyA7Uq1eNhwn82ES1LGSMB+A6jmZ9hLwC1QHG/V7o0XhTNJYVd95CF3e8udJTyffL LTIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b="gEPEyL/J"; 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 k19-v6si4743738pgf.324.2018.08.08.08.37.38; Wed, 08 Aug 2018 08:37:52 -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="gEPEyL/J"; 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 S1729673AbeHHRyK (ORCPT + 99 others); Wed, 8 Aug 2018 13:54:10 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43641 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729609AbeHHRyI (ORCPT ); Wed, 8 Aug 2018 13:54:08 -0400 Received: by mail-wr1-f67.google.com with SMTP id b15-v6so2389708wrv.10 for ; Wed, 08 Aug 2018 08:33:57 -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=0gvZONlvYfavZIv9YJMRdLBNbGF8vyYhSH/TZ/EBwZA=; b=gEPEyL/JokYkdCKr49rlPlBQcmVPQq092r43UkxD367PT4KOvaSD7l4mHIrepfh+qk O3PCLryWHVpOtDaGaSIy6FSAIBFh2+OCX3SnIMDHW6BWtgtN0kAaUTAycsyEthK7bOHU Tj387dMBc2P2mOx9zoY88ky4aDSN6RlO1SaCXRqm0hvynIJ/XLzP2R8CvgJyp/nTkoBQ oBZUomwCAWMLQ3rjtkjmanRkF2c7JF6wIONQxrLUinjiatX8iT6FGETuLFGdmd0RW1GW rO7GskZbkXv6VepMIm8DPMc4tFNMt1t3ZZOmH95M29McJWd16P0G1AgBB8cJYK/u8MLk DeSw== 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=0gvZONlvYfavZIv9YJMRdLBNbGF8vyYhSH/TZ/EBwZA=; b=mjHGZSLpfRsRgplEoFdFjmucinnB8D42WxLdcx4oD+aeJqsNRWMHRWCmYsA9/SA+MN OCe3i0XwCp3ncvmWT/VSKSx8XUloOK3NxUfgGvWqDPApyW00O45JB1oc6NpqNTOlXOZ4 3ACqYaHvSslc4V7zYNtaH7sb6GgWqyhJQByIUEvRQoS0KqZhUbK587+PVji5UwkybKwN yp/D+GT5DjqCKIJvdnNaDLdhE8JTs9g0cnYyTy4kSvP+/wUM5D9eQXIT8CaodqkNX1tk 1Fx1dlzNQnk0vg/02zjHI7zowFKqlnlifolVCQEK80JQrFhrkgwj7AEMHYSnjGVdZqNx 7f4w== X-Gm-Message-State: AOUpUlGQ9vkbEygXLIvj/DgOdQSvZeplSbqgn8j1PAaW8n4AVRQSUTa2 jqa8YLrt139AbBoFtWhsxf/l/A== X-Received: by 2002:adf:f850:: with SMTP id d16-v6mr2110252wrq.172.1533742436383; Wed, 08 Aug 2018 08:33:56 -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 s2-v6sm5240915wrw.52.2018.08.08.08.33.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 08:33:55 -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 15/28] net: add support for nvmem to eth_platform_get_mac_address() Date: Wed, 8 Aug 2018 17:31:37 +0200 Message-Id: <20180808153150.23444-16-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180808153150.23444-1-brgl@bgdev.pl> References: <20180808153150.23444-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 cf54cdf042b7..98bc280b8a62 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -559,6 +560,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; @@ -571,6 +605,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