From patchwork Thu Jul 19 15:32:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10534803 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 829D26053F for ; Thu, 19 Jul 2018 15:33:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2289D298EB for ; Thu, 19 Jul 2018 15:33:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F528298D0; Thu, 19 Jul 2018 15:33:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4225298D0 for ; Thu, 19 Jul 2018 15:33:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732048AbeGSQQr (ORCPT ); Thu, 19 Jul 2018 12:16:47 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36024 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731930AbeGSQQh (ORCPT ); Thu, 19 Jul 2018 12:16:37 -0400 Received: by mail-wr1-f67.google.com with SMTP id h9-v6so8526200wro.3 for ; Thu, 19 Jul 2018 08:32:53 -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=1xdS95FRpW8FEMlxpDl9MSMdZJkHd3nUIrG//p44OVk=; b=Mf4LcwYtI7fqLwkE+HSaK4s0I8Bicptyee6tPc0IkelFmX/G1EW9HXwoYCJAzCrGCA S476KiOeVP8XyXQIgp8YvNRWP00u9YGw+c28alk2N43krVZ+jVUMbRXUiMmNIlWHgqjE sXWZ4TNMH2T6Diq5pGLD5HZePnKp5yVbnZbK/67ex+Pm9pl2HcafaAvhoh3eF4Q8mmj0 yOTbgL8gNg4PTKYer+Jb+AsFuTIHHmZgaxgaq7xFNrzXO37J7LvX7Cf/3glbzZvYRqai BdA7uLY/8GqCjM11SMJ/ssn8U9WMqjrQafFIvgryHz+hSgw0TRV45jwE+2iZpjx+fxG1 E+mg== 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=1xdS95FRpW8FEMlxpDl9MSMdZJkHd3nUIrG//p44OVk=; b=V2D+dDAWORP99jU2ceSUsonSZ3Ztce9irOCzoLpmm1GiIbsCjH55r18yHE9mGrGMja o4GxL6JbnvkGeVElrfDlK9ufcE7PAyW0Rp5BBivxjfSFFD1z4GOZt3Ah0KouFlqK8bSN rur5cqksVXE16r1ECKoIA/GuAxuqKWRIHa808+3xPxZ12gvBiQttWNpB/Gv1I5z83MT5 lQxYcZvfD9bZ8WWv3iszfLDwy+4j/xNQI43RWiNl/Z9XC4LdgtjTciViISB/8zFkApHW 4URI1TW+JTg0QU1hgOpNy1mdljFNDZdeO8CVHYV0Lim6AoWjnwEf6oR36HXOMD0VztgG n5PA== X-Gm-Message-State: AOUpUlGn0rHc39K45ZWpsH+tuaTwRLAbBUCALydPHAlPKfr+rS/VT7cC 7K8O7bPA7CUDaOHELdO9Q+GOpA== X-Google-Smtp-Source: AAOMgpdexKV1aSpZwz4I7gGFEQ6AMCcnGg3sbhzR7U2/Etll8f7BWmLCTpXw1ZkXRck9FOGT8pq2Wg== X-Received: by 2002:adf:8481:: with SMTP id 1-v6mr8175290wrg.34.1532014373323; Thu, 19 Jul 2018 08:32:53 -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 w9-v6sm8914090wrr.77.2018.07.19.08.32.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 08:32:52 -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 v3 2/3] net: add support for nvmem to eth_platform_get_mac_address() Date: Thu, 19 Jul 2018 17:32:42 +0200 Message-Id: <20180719153243.20944-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180719153243.20944-1-brgl@bgdev.pl> References: <20180719153243.20944-1-brgl@bgdev.pl> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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);