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: 10534809 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 A3C3E600D0 for ; Thu, 19 Jul 2018 15:33:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9043829648 for ; Thu, 19 Jul 2018 15:33:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84E6E29847; Thu, 19 Jul 2018 15:33:53 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3ABFC29648 for ; Thu, 19 Jul 2018 15:33:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=xQpkAS9AQwr3ocbC5y22ZNGngUjScx6/iTGXk5XKyx4=; b=WKRDQSR+xYId8yVMFYqziJTIby VeKxTNjrfVJsoubwSaiCgr9oHEPY3o9x+vkjo1cw6MFGKEQuCBiOzQvgEfyN/CNylCJwsYp0Ckh98 e0KVVGKIGj7u57yshpPZonGS7w1bC8gNcMNhCaFYLDNUkF1yEdbwOIaO9LBrlK4RokEeFf7pctDae R7JwYOxgU6fN134aLmD9KPYiybHakjL0z/aktpM/znvwVPviBzPVsaNA0zQDXq4unmhAqt+UKVAy2 s9n+P9hs/N0Xi88ud/nL64BNRIE5FLG66Iw5Tk0XSVy1K2Y2qjfMfuP9mLMWtQZ0DOI0gK3GoJl3H jCxMJPEQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fgAw9-0004zv-TI; Thu, 19 Jul 2018 15:33:49 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fgAvR-0004Dh-2W for linux-arm-kernel@lists.infradead.org; Thu, 19 Jul 2018 15:33:08 +0000 Received: by mail-wr1-x441.google.com with SMTP id s11-v6so8480429wra.13 for ; Thu, 19 Jul 2018 08:32:54 -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=HELuoouC/yupMC12yCmz/jgqcsM8YzzCVkKAARjV9rSG8swah20Oa2EHuTh/co7hX5 LqRGTJgXW+NqYDZF/qL8V1k9tn+lyqAlb/y0AKxVuMAJ3d/xsjNRO6zPWtJR3adu4GLz duCQXXLqMagHtZLa8eaXfBILgbeS/T/I6BXHATAuDaMiJ7rKgXw8oZf3bkJHmGFgwSTu xxN4Op7x0/jCSUkv8K6W3rHNacY66LqIWoqZWg6R8GJsHanUKNwlLqkcoGLMETQn04Xw 4Pz2DGCWVRDgfxTT6OAF5718jFHBKgHlTCQVKB0oQV7poVk4G6CInjadXM0l5ZLswa12 Qjkw== X-Gm-Message-State: AOUpUlHZ3/Q6r02oIqECUfYZUFtSB5FOOxdY08lPa9DxGfzfqnOCqyVB w0+hIjHDbhbSeAZWvjOhkbWCxg== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180719_083305_586912_73D05FD2 X-CRM114-Status: GOOD ( 16.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Bartosz Golaszewski MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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);