From patchwork Fri Aug 10 08:05:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10562401 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6E56E157B for ; Fri, 10 Aug 2018 08:08:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CC972B663 for ; Fri, 10 Aug 2018 08:08:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D4042B660; Fri, 10 Aug 2018 08:08:10 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 E3B222B660 for ; Fri, 10 Aug 2018 08:08:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728315AbeHJKet (ORCPT ); Fri, 10 Aug 2018 06:34:49 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:39065 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728302AbeHJKet (ORCPT ); Fri, 10 Aug 2018 06:34:49 -0400 Received: by mail-wm0-f66.google.com with SMTP id q8-v6so940098wmq.4 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=C3SwGabCPWjz2lQgSY7GSId7Of6czflBQvkC2hQgZQe4PPCYMCIrwOeCHDxsVuBC// 8qpac2ZWY+cST7KvEqF4xKOe9xWbIEK/e0aps2YKp8SjRlgKp/8fZJPLbIM2cG2zLI1h 2qloNkZ/byYLUKFNgM/a2SxFdJuhQFcjGSgwzAM9pqbbMI/4U6/aDoxm6+zgV8n0wB4N 1RaEfj4yE2heinLU62wCzMG4K5TN16iLHYgty9TVPdH4BcuDGu4uTcSIqkIv7TTnHOjf XMsXqCEk0uCM3pwdbSWrpmmtVsplxbhQFOhN9bgosmD3YbkZw8ES9euFt9v0b2VOUCQ/ TlMA== X-Gm-Message-State: AOUpUlFS7W8KYU7QyWfNHIC1huQjjc59M+IH4m7dJIp1WxBK6POnI0bR FV40DUswCKNqYUyo6Ot2sF2sPA== X-Google-Smtp-Source: AA+uWPwkRZbXh5LSdlohK1hTKspc6zrxfOZHz6Dm0nnhPL1EtFPJittRNfRlO54QLRBPf0Hyd4OjWQ== 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-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 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);