From patchwork Thu Jul 19 15:32:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10534795 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 0FE0A6053F for ; Thu, 19 Jul 2018 15:33:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1A87298D0 for ; Thu, 19 Jul 2018 15:33:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFDD829CCE; Thu, 19 Jul 2018 15:33:05 +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 7D9CF29C89 for ; Thu, 19 Jul 2018 15:33:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731849AbeGSQQj (ORCPT ); Thu, 19 Jul 2018 12:16:39 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:40027 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732013AbeGSQQi (ORCPT ); Thu, 19 Jul 2018 12:16:38 -0400 Received: by mail-wm0-f67.google.com with SMTP id z13-v6so6850954wma.5 for ; Thu, 19 Jul 2018 08:32:55 -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=NGCfKMPNiphpkZq3ixyFo1n5Jq09hNfE9390fzLN6Wk=; b=DER6VvK11nXQ+52alJZkPHCLuF/+CR/GSCeAxBiONaDF38xKTd7NPb0aLms3MjWmxG qLyM8l8IEcyBdHcIG3CE7KjP/iPIp2rtrA8orGxfNSsGon6yBwhXehbIljeEGObG3zL8 R8R4oqBM50tkmQkl4jhoYjJNAr5bnUqf4X7FdxfK618xW+YwN2yEfELbDtc1ob1/jlwM Z+DGQkPVs0ZbGBB7zvgjZ7+lYKUQ0Bs9P0/NtYi66kv3xMmnhFXX0+8ee8YtNzFjLvi8 7X5EqQZ2X2rBu9q6b+Oo49Drq2ctrPPV+4RNEPWPHsgP072tLcQ0wUL0sQuYJDaDEsB+ 2cGQ== 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=NGCfKMPNiphpkZq3ixyFo1n5Jq09hNfE9390fzLN6Wk=; b=Wd6++mP+YHKI6ZxqEmo50LmyVd44QIX4ho1KKyRYYxNqEZVvifNiZCdtNlzLmtFPvP /iTfGfZhY/tVXcU9tdDZ7JAwWiyqOpGOKw6zlmBVADlULOxcfcgnpRx4nSCRACt6OzZ5 UKLN0bpeyEDaTbf2HWRJ0Etn5Rduiz3ymbYNXyJT2+zS6Zd9sP8DeagT4G0iZNp+SEQp Dc5EoZWD+mu+97bsODkwx0RhPEtGN8QJwhzKgXir3JVATXKc7Eg7i8iiXzUQkawR4rD3 pPDKIz/O8J4wTET2iZqMz5wgt4IIz89pss20lcdFEfrcDDvQmqTMgu80oA34/t3+W0W+ jcpw== X-Gm-Message-State: AOUpUlHF6omkc/nvvA1+tcA63yTAa6AHYuU9JUiB5O44le8EDjtNqTyh /6J4FT6L+smDc9K2IYlNGe/9nQ== X-Google-Smtp-Source: AAOMgpcyw5TKoN9PrZtzMZJspIArdfBp0K9dVmNhexMfhj2iFOSx2yOPOu42J6dY2+Jp/WT9M6RLkg== X-Received: by 2002:a1c:8010:: with SMTP id b16-v6mr4824280wmd.9.1532014374692; Thu, 19 Jul 2018 08:32:54 -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.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 08:32:54 -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 3/3] net: add MTD support to eth_platform_get_mac_address() Date: Thu, 19 Jul 2018 17:32:43 +0200 Message-Id: <20180719153243.20944-4-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 MTD doesn't support nvmem yet. Some platforms use MTD to read the MAC address from SPI flash. If we want this function to generalize reading the MAC address, we need to separately try to use MTD. Signed-off-by: Bartosz Golaszewski --- net/ethernet/eth.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index 98bc280b8a62..a0d5e4477afc 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -593,6 +594,36 @@ static int mac_address_from_nvmem(struct device *dev, u8 *mac_addr) return rv; } +#ifdef CONFIG_MTD +static int mac_address_from_mtd(u8 *mac_addr) +{ + struct mtd_info *mtd; + size_t alen; + int rv = 0; + + mtd = get_mtd_device_nm("MAC-Address"); + if (IS_ERR(mtd)) + return PTR_ERR(mtd); + + rv = mtd_read(mtd, 0, ETH_ALEN, &alen, mac_addr); + if (rv) + goto put_mtd; + + if (alen != ETH_ALEN || !is_valid_ether_addr(mac_addr)) + rv = -ENODEV; + +put_mtd: + put_mtd_device(mtd); + + return rv; +} +#else /* CONFIG_MTD */ +static int mac_address_from_mtd(u8 *mac_addr) +{ + return -ENODEV; +} +#endif /* CONFIG_MTD */ + int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) { int rv; @@ -609,6 +640,6 @@ int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) if (!rv) return 0; - return -ENODEV; + return mac_address_from_mtd(mac_addr); } EXPORT_SYMBOL(eth_platform_get_mac_address);