Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1435147imm; Thu, 19 Jul 2018 01:22:48 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdetZVP34nLUm4iIfcMnjcEJuf5zmnxmk7GnFxMQ2pBJjXlzflV4GiM9pRPCz88zYxwKt8o X-Received: by 2002:a63:571d:: with SMTP id l29-v6mr8738799pgb.296.1531988568587; Thu, 19 Jul 2018 01:22:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531988568; cv=none; d=google.com; s=arc-20160816; b=d5mYYduD2mgqb3gRiFIPdivFZfINzdm9fA/qsMjau/1+4NLchrLLOzBi5CFHv/5L32 PM1WTuOOBH79VOXzNz7W8iCYZJtwaUoy3nvIfNsliQSVlOWk7MLOLeE+ekWtW01+ZMZd eCvxbQStk0Ket29TDpQsleH0fURBkUgWBQ6z0MLtk+xYIFNfjJ7r3DPI2xyctkOxzKnQ Ss4G8NHqAdVozVrZbqyFL1qPnp05Vc0NOID7ygnC0O7Fqr3RVw9AqJhOS/ws7P4kHxXU 11cNHUaYcqoyjoWbFPygFMn8qxpGGbhG5Jw6HrDK8WaHBr7HiEaO+WjPEmQGA0TC7HBI n2KQ== 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=6aX5BtucoOQijr14hJLQWkiX22ZRMT0Pi0ieKWGm2A8=; b=k+FpcNOoo+ByGgZXp1G8Br4qJVsSoZ7yG9F3XGmLmG2sTgqC1HqjWALRjSr8cYavfg /JU2OaUo246HkXaHn6eZfKaJVyKShZclEOj4sSCvL84dR8RyJ8I/lLuyr3LIq+P23aKV 7c3Qc53TZz+YkbazcSdJWk/RWa9+LOdHAMolPlesH0M/+AUun2xnRytBeOwA2bRUVXkY TaXeDJAj1vM1DNgkyJuXACsTjf/MCOnthZw1JfH/Xzbm+rjDFWafFpQWed+Ah2FzdT67 7HHGZnL/sZmriDanOg2H7RhfE/hf40jw7TV17PADd9WmbNdzZ1NPBgXF8U7S6YT92+vg Dg8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=XZ4vKeDV; 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 x186-v6si5220254pgd.259.2018.07.19.01.22.33; Thu, 19 Jul 2018 01:22:48 -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=XZ4vKeDV; 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 S1731588AbeGSJCf (ORCPT + 99 others); Thu, 19 Jul 2018 05:02:35 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33964 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731479AbeGSJCe (ORCPT ); Thu, 19 Jul 2018 05:02:34 -0400 Received: by mail-wr1-f67.google.com with SMTP id c13-v6so7141253wrt.1 for ; Thu, 19 Jul 2018 01:20:35 -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=6aX5BtucoOQijr14hJLQWkiX22ZRMT0Pi0ieKWGm2A8=; b=XZ4vKeDVThbroNNkg12Q/lIkPtkRFVcqrvmiIPVLOt7+hb9dqDHmUpfmbsFiMQA2Vj aAlGaWvXNKSzzUrSmtVtpAWNrB3caagzy3HnnVFpLg3zO4R1clc2mcfVwACRgnhlVO42 B2Os09Sp0xecdo0stMvYdT2WKdE5XRGTKteoT9W4nB/u9svAYqhFpa/R4YvppZybky1b QwSP9dYTeGkxuhIoGIS1S2NBIoewNtdkHX5gKNPXOIewfGhgvR+lm251Fwz4oJBU0NWX mnZFifn1SGVUmUtsxF4eSVr0XbDdGu61jUMzIO4wek4NZLFydFkYusOKRehpWnUsjjmy O4rw== 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=6aX5BtucoOQijr14hJLQWkiX22ZRMT0Pi0ieKWGm2A8=; b=VlZ7yjgBsLo8GbRVJNBH9NxyyfMVt6EqaR+TYkyv2oS7MTTcJypP9/9Cx05HxbV2S8 iitE/voQm4wHiTHN/hOFaseZSxH4ivovis9277nICzm/8OrLsEPiQHJK1Z+7pZyo8DSd By1n1HPpCN9KmSswCpIT9zxVVs0bQWvwe1UVlGStsjnRoZeNKHNhr4bWjz2vp0jhA39s DSq2tJCke/3+22+5+Wd9qqttOh+bGX3lFtYnA13JnmZ+Jkwu4JbhRRB9n+1wzQ4bEMWO UjGeFFZTXevtamAYg+stgjilLImo27yQF/8JPAnrJu2mk8VhzwDO2rtRsvgr7DC04uVu Bepw== X-Gm-Message-State: AOUpUlEYvIad1PT3MHrB8emI6QM4xS0AgrLzxtl924NI7htJ/tuvdsWd 9e19y8P5sMGZ1SJKzMcuaMFaUg== X-Received: by 2002:a5d:4cc5:: with SMTP id c5-v6mr6995087wrt.210.1531988434522; Thu, 19 Jul 2018 01:20:34 -0700 (PDT) Received: from brgl-bgdev.baylibre.local (AStLambert-681-1-40-185.w90-86.abo.wanadoo.fr. [90.86.159.185]) by smtp.gmail.com with ESMTPSA id h43-v6sm1716338wrh.1.2018.07.19.01.20.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 01:20:33 -0700 (PDT) From: Bartosz Golaszewski To: Sekhar Nori , Kevin Hilman , Russell King , Grygorii Strashko , "David S . Miller" , Srinivas Kandagatla , Lukas Wunner , Rob Herring , Florian Fainelli , Dan Carpenter , Ivan Khoronzhuk , David Lechner , Greg Kroah-Hartman , Andrew Lunn Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, netdev@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 2/3] net: add support for nvmem to eth_platform_get_mac_address() Date: Thu, 19 Jul 2018 10:20:27 +0200 Message-Id: <20180719082028.26116-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180719082028.26116-1-brgl@bgdev.pl> References: <20180719082028.26116-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 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index 39af03894598..af3b4b1b77eb 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -527,8 +528,11 @@ unsigned char * __weak arch_get_platform_mac_address(void) int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) { + unsigned char addrbuf[ETH_ALEN]; const unsigned char *addr; + struct nvmem_cell *nvmem; struct device_node *dp; + size_t alen; if (dev_is_pci(dev)) dp = pci_device_to_OF_node(to_pci_dev(dev)); @@ -541,6 +545,29 @@ int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) if (!addr) addr = arch_get_platform_mac_address(); + if (!addr) { + nvmem = nvmem_cell_get(dev, "mac-address"); + if (IS_ERR(nvmem) && PTR_ERR(nvmem) == -EPROBE_DEFER) + /* We may have a lookup registered for MAC address but + * the corresponding nvmem provider hasn't been + * registered yet. + */ + return -EPROBE_DEFER; + + if (!IS_ERR(nvmem)) { + addr = nvmem_cell_read(nvmem, &alen); + if (!IS_ERR(addr)) { + if (alen == ETH_ALEN) + ether_addr_copy(addrbuf, addr); + + kfree(addr); + addr = alen == ETH_ALEN ? addrbuf : NULL; + } + + nvmem_cell_put(nvmem); + } + } + if (!addr || !is_valid_ether_addr(addr)) return -ENODEV; -- 2.17.1