From patchwork Fri Nov 30 08:20:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10705945 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 EE12B1057 for ; Fri, 30 Nov 2018 08:21:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFB7E2FBF1 for ; Fri, 30 Nov 2018 08:21:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFF0F2FBFF; Fri, 30 Nov 2018 08:21:22 +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 385272FBF1 for ; Fri, 30 Nov 2018 08:21:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727041AbeK3T3u (ORCPT ); Fri, 30 Nov 2018 14:29:50 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:53490 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726971AbeK3T3t (ORCPT ); Fri, 30 Nov 2018 14:29:49 -0500 Received: by mail-wm1-f65.google.com with SMTP id y1so4813482wmi.3 for ; Fri, 30 Nov 2018 00:21:19 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=Ccuz9dZlPq5ZTOzECk8TCynM67LjW14hECdEnE8yAoo=; b=uX7QS7g4JDsPrxezfmeCVmdxMKHX0QZ3kZ6AfJtpusnADX1lEV8tF79PS2JbrpqIY7 Q5nYud/F2oFMyW8keHTPVAq4jk81aYEx4zW2HInP5+PJyVGehVT30JBtTr2h7PwgflIo XgjYte0RcD5NpvCC4gqrCaYL7y7eTeUADR887kVBvamV4s1+2ZMsBicHgwatcyZ9vovq wc88AOijPR7YcG8NRa4p7tbkb9yjOe/RhLKu8EbsUnCJly64cAVaNwiHhypwxYihLSpW eBnWt28r/oCyYoQftm/8nWtK/x2l7UCvBxiuHTaT6Av8E+/LbEDfnxEiyXqI7qONXYSC WwLw== 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:mime-version:content-transfer-encoding; bh=Ccuz9dZlPq5ZTOzECk8TCynM67LjW14hECdEnE8yAoo=; b=SHHzfwItsXxVX4EUJpdFAbZ0j3susxW8dKiwhTVifOFk9yPgoKYfQOgxU4cjuXNOkP x+/dQ0F41t/vQqSBbNA3SBc3sviYpL88+8/mQUGo5xho3pAdO6g2EP29pTddUG2urICk UQDlz5FuBCrXRYpMtHeN6nnRXDndDLo1WAsnIIHHgaG253ep5UnLoSLelQQ16th+G3k+ qPdOgvtWMjdRjOEAidvubdu+1TqzRzdacqt7F3xtrO8wZsWA1XOmR0pLMqbWNLa0RnII uNAil9GrSCCPPWy3yL9f+NWFxOHSsmXR9l3/r1ayr7nucWZBLh4nR1lk0fjdSLKEvDMX 397w== X-Gm-Message-State: AA+aEWYvp+3OBjirliqJbskxWecj0XxnBLBcUYaRqy33n0BC+yks/6TX vt9ABWgpg5Yj55oDM5ihXiSmXA== X-Google-Smtp-Source: AFSGD/WSQb4UKxUJp/cZxMhoCDD6o9879iKyE70hXRqynkc8QHsrqcU9k/BhxMJDtgeuSzFpRHOBzQ== X-Received: by 2002:a1c:9314:: with SMTP id v20mr4695071wmd.15.1543566078364; Fri, 30 Nov 2018 00:21:18 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id x197sm6473374wmd.2.2018.11.30.00.21.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 00:21:17 -0800 (PST) From: Bartosz Golaszewski To: Grygorii Strashko , Nicolas Ferre , "David S . Miller" , Andrew Lunn , Florian Fainelli , Heiner Kallweit , Rob Herring , Frank Rowand , Sekhar Nori , Kevin Hilman Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-omap@vger.kernel.org, Bartosz Golaszewski Subject: [net-next][PATCH 1/4] net: ethernet: provide nvmem_get_mac_address() Date: Fri, 30 Nov 2018 09:20:57 +0100 Message-Id: <20181130082100.6241-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181130082100.6241-1-brgl@bgdev.pl> References: <20181130082100.6241-1-brgl@bgdev.pl> MIME-Version: 1.0 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 We already have of_get_nvmem_mac_address() but some non-DT systems want to read the MAC address from NVMEM too. Implement a generalized routine that takes struct device as argument. Signed-off-by: Bartosz Golaszewski --- include/linux/etherdevice.h | 1 + net/ethernet/eth.c | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index 572e11bb8696..2c0af7b00715 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -32,6 +32,7 @@ struct device; int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr); unsigned char *arch_get_platform_mac_address(void); +int nvmem_get_mac_address(struct device *dev, void *addrbuf); u32 eth_get_headlen(void *data, unsigned int max_len); __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev); extern const struct header_ops eth_header_ops; diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index fd8faa0dfa61..df38593d1bb4 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -548,3 +549,40 @@ int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) return 0; } EXPORT_SYMBOL(eth_platform_get_mac_address); + +/** + * Obtain the MAC address from an nvmem cell named 'mac-address' associated + * with given device. + * + * @dev: Device with which the mac-address cell is associated. + * @addrbuf: Buffer to which the MAC address will be copied on success. + * + * Returns 0 on success or a negative error number on failure. + */ +int nvmem_get_mac_address(struct device *dev, void *addrbuf) +{ + struct nvmem_cell *cell; + const void *mac; + size_t len; + + cell = nvmem_cell_get(dev, "mac-address"); + if (IS_ERR(cell)) + return PTR_ERR(cell); + + mac = nvmem_cell_read(cell, &len); + nvmem_cell_put(cell); + + if (IS_ERR(mac)) + return PTR_ERR(mac); + + if (len != ETH_ALEN || !is_valid_ether_addr(mac)) { + kfree(mac); + return -EINVAL; + } + + ether_addr_copy(addrbuf, mac); + kfree(mac); + + return 0; +} +EXPORT_SYMBOL(nvmem_get_mac_address); From patchwork Fri Nov 30 08:20:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10705951 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 AB73F13BF for ; Fri, 30 Nov 2018 08:21:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DFB32FBF1 for ; Fri, 30 Nov 2018 08:21:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91FB02FBFF; Fri, 30 Nov 2018 08:21:48 +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 1A7822FBF1 for ; Fri, 30 Nov 2018 08:21:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726590AbeK3TaR (ORCPT ); Fri, 30 Nov 2018 14:30:17 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:42706 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727038AbeK3T3v (ORCPT ); Fri, 30 Nov 2018 14:29:51 -0500 Received: by mail-wr1-f66.google.com with SMTP id q18so4370697wrx.9 for ; Fri, 30 Nov 2018 00:21:20 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=lJyx3gFlIK2rFy1vMeWyk8uHK8wEfTaZ3rmQd4bUKx4=; b=Uylz24i3Z8nlWHeBua5/oHwAl1P6w3quwD9Ohz1BD7tzbovLsSPX9/gU9WLtYyEEMx S2tiG67UL2pbV869G763TIQKa2F1V5hz4g3yM3NodQngSVXkUEUXNi64u4KgufleykUi V8EkFPjKtwDZUujFd8RZ/M+CYn46fOZYOZln3gx4ejhJs/3oaDaNzuNwzMx5kmitOMhF DCtdNFV5jUmjMAh8UyXQ07tRoVqXvmenQluwTtOOTMtRQElRvJYSJUttk2zdyMfXg9lj Re3rhLZuC3nCllfCtphzsm90GDYQ9RRNlp6OSLov6GU249/RNbg61TtuBAMJsr77FpDl VL2w== 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:mime-version:content-transfer-encoding; bh=lJyx3gFlIK2rFy1vMeWyk8uHK8wEfTaZ3rmQd4bUKx4=; b=r8EJIo+jecMH93ieUJ4x4rpARqSvdG9DahyUGajZ7+B9smQMbO3MYDsINT8QrSepog 2cm/XE+JNEgRo938RlxJzbsQPqox/XxiLDE1e6KXcUxw3POGqR/Tg094r3Tm304zocdA JOB9TctWOVOS3qsQZ18uOJFRMmW0VUAspTslQcISXCyQ8ZjfB5TM62W7tT1wOv+qmh51 lBAnHZoghEiuWcG5Yogl6pZwd4eViz30YC3vjiKsWfEYwY0ODtsSqR4EiEBY1BOSUPNk 1hC9CrngEJOZXxNrNUBb3q6OzMHC+7xFChZhAyEVziy7hGgPnmECxDYUrPsrfi44AmII Qmfg== X-Gm-Message-State: AA+aEWanKsI4eBSafEBTZaNrVJAZNlY19u1+SQutX1r2bfoLrv9dTvkc VCbm4BPoAiHONPTNkvprN8TWIQ== X-Google-Smtp-Source: AFSGD/WEGYJST2pq6nf7GYDCkLFIHvejs7k2Oh5l/VtmBG8TP/pq/RFvdlPU9WEumMa0mH5hI9KRnQ== X-Received: by 2002:adf:cf0f:: with SMTP id o15mr4163625wrj.253.1543566079516; Fri, 30 Nov 2018 00:21:19 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id x197sm6473374wmd.2.2018.11.30.00.21.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 00:21:19 -0800 (PST) From: Bartosz Golaszewski To: Grygorii Strashko , Nicolas Ferre , "David S . Miller" , Andrew Lunn , Florian Fainelli , Heiner Kallweit , Rob Herring , Frank Rowand , Sekhar Nori , Kevin Hilman Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-omap@vger.kernel.org, Bartosz Golaszewski Subject: [net-next][PATCH 2/4] net: cadence: switch to using nvmem_get_mac_address() Date: Fri, 30 Nov 2018 09:20:58 +0100 Message-Id: <20181130082100.6241-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181130082100.6241-1-brgl@bgdev.pl> References: <20181130082100.6241-1-brgl@bgdev.pl> MIME-Version: 1.0 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 We now have a generalized helper routine to read the MAC address from nvmem which takes struct device as argument. The nvmem subsystem will then try device tree first before all other potential providers. Signed-off-by: Bartosz Golaszewski Acked-by: Nicolas Ferre --- drivers/net/ethernet/cadence/macb_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 1d86b4d5645a..d9a208f7bb40 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -4055,7 +4055,7 @@ static int macb_probe(struct platform_device *pdev) if (mac) { ether_addr_copy(bp->dev->dev_addr, mac); } else { - err = of_get_nvmem_mac_address(np, bp->dev->dev_addr); + err = nvmem_get_mac_address(&pdev->dev, bp->dev->dev_addr); if (err) { if (err == -EPROBE_DEFER) goto err_out_free_netdev; From patchwork Fri Nov 30 08:20:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10705949 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 EAE0A13BF for ; Fri, 30 Nov 2018 08:21:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA46A2FBF1 for ; Fri, 30 Nov 2018 08:21:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC3C52FBFF; Fri, 30 Nov 2018 08:21:40 +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 68B102FBF1 for ; Fri, 30 Nov 2018 08:21:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727172AbeK3T3x (ORCPT ); Fri, 30 Nov 2018 14:29:53 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:55233 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727085AbeK3T3w (ORCPT ); Fri, 30 Nov 2018 14:29:52 -0500 Received: by mail-wm1-f66.google.com with SMTP id z18so4835256wmc.4 for ; Fri, 30 Nov 2018 00:21:21 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=hgb7Jf4JzQq+BZf3FS+sr7z0n9uuyVnC5JrBI/ymMjs=; b=w3qBpdwxixKSwtAr2cNDwRPb862aZc1l5jZUSeftGTT+U5xnaxdDyMnk0xCVgQ6Qr1 SIpGBUmLI2/wwgvA7w/IDXtewl1fq4HIJLwy/U+iipgBZWPVgRk90vzPSB2AHS6MZhq9 SPiMYg05c7lYy/rudI0Zsfq36kIQPgV3HJVlrjDKDeYId4r3huxbFbhvYt8GHoB7sd6J 9U7QDoWPPlrCdFuVh11U8e7SRCNXcYGPlT6M2ZeBZot1EJCdo/qabOEUO8BIYDHo81BV WAdl3WIDrqfHscg45CxbMYHTcHzQRscZqOg0P/CXmAHugm8/xjTrJp0BAwDYN89bjRoI nGQQ== 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:mime-version:content-transfer-encoding; bh=hgb7Jf4JzQq+BZf3FS+sr7z0n9uuyVnC5JrBI/ymMjs=; b=fIFkyQMy/d5TdM13reWEfBcGiVtj6axVQvEjMEFQyCzlNLZRZ5wL+DcSoCFM6v0z5e ZXj1f0gbCUCJCihl5stO6YmTaafV1N227gbFSe6LcCJyBDkqAk1ubDEjK6VyglLICBP1 iJl8v2faxEnvxTpPV9N9YosJN3COEz9W6BDCr7A8x4KIZ1uVpi3W5oeF94BiWJLnVbW0 p5/GA6qSPdzBFcifoeFxUQe+vRdScjp6az5B7c6xxjyHytWeIPASsa7v7LqOhpCUkiUO AxwlgdlyfdCMg+xTXW6f0utIymp8CMLF9Vp0cbFFw0ChPvW1HdXqFpFYM+jpnuM2/PuO n2Gg== X-Gm-Message-State: AA+aEWakUK4xBSxkhH1pvPRUjw2pDchmyxfKzyvAyO37G8aAfwU2C/eD QK8JqrnN270+7OmY/Oh58+FegA== X-Google-Smtp-Source: AFSGD/ViqOg8nrUwEf+F8iUN8aKfzpJNyeWswKQvwjj7Pb3cp37fFbccS3X9uNfsKPQHRgnDZzfwuQ== X-Received: by 2002:a1c:df46:: with SMTP id w67mr3264485wmg.51.1543566080748; Fri, 30 Nov 2018 00:21:20 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id x197sm6473374wmd.2.2018.11.30.00.21.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 00:21:20 -0800 (PST) From: Bartosz Golaszewski To: Grygorii Strashko , Nicolas Ferre , "David S . Miller" , Andrew Lunn , Florian Fainelli , Heiner Kallweit , Rob Herring , Frank Rowand , Sekhar Nori , Kevin Hilman Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-omap@vger.kernel.org, Bartosz Golaszewski Subject: [net-next][PATCH 3/4] of: net: kill of_get_nvmem_mac_address() Date: Fri, 30 Nov 2018 09:20:59 +0100 Message-Id: <20181130082100.6241-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181130082100.6241-1-brgl@bgdev.pl> References: <20181130082100.6241-1-brgl@bgdev.pl> MIME-Version: 1.0 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 We've switched all users to nvmem_get_mac_address(). Remove the now dead code. Signed-off-by: Bartosz Golaszewski Reviewed-by: Rob Herring --- drivers/of/of_net.c | 39 --------------------------------------- include/linux/of_net.h | 6 ------ 2 files changed, 45 deletions(-) diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c index 53189d4022a6..810ab0fbcccb 100644 --- a/drivers/of/of_net.c +++ b/drivers/of/of_net.c @@ -81,42 +81,3 @@ const void *of_get_mac_address(struct device_node *np) return of_get_mac_addr(np, "address"); } EXPORT_SYMBOL(of_get_mac_address); - -/** - * Obtain the MAC address from an nvmem provider named 'mac-address' through - * device tree. - * On success, copies the new address into memory pointed to by addr and - * returns 0. Returns a negative error code otherwise. - * @np: Device tree node containing the nvmem-cells phandle - * @addr: Pointer to receive the MAC address using ether_addr_copy() - */ -int of_get_nvmem_mac_address(struct device_node *np, void *addr) -{ - struct nvmem_cell *cell; - const void *mac; - size_t len; - int ret; - - cell = of_nvmem_cell_get(np, "mac-address"); - if (IS_ERR(cell)) - return PTR_ERR(cell); - - mac = nvmem_cell_read(cell, &len); - - nvmem_cell_put(cell); - - if (IS_ERR(mac)) - return PTR_ERR(mac); - - if (len < ETH_ALEN || !is_valid_ether_addr(mac)) { - ret = -EINVAL; - } else { - ether_addr_copy(addr, mac); - ret = 0; - } - - kfree(mac); - - return ret; -} -EXPORT_SYMBOL(of_get_nvmem_mac_address); diff --git a/include/linux/of_net.h b/include/linux/of_net.h index 90d81ee9e6a0..9cd72aab76fe 100644 --- a/include/linux/of_net.h +++ b/include/linux/of_net.h @@ -13,7 +13,6 @@ struct net_device; extern int of_get_phy_mode(struct device_node *np); extern const void *of_get_mac_address(struct device_node *np); -extern int of_get_nvmem_mac_address(struct device_node *np, void *addr); extern struct net_device *of_find_net_device_by_node(struct device_node *np); #else static inline int of_get_phy_mode(struct device_node *np) @@ -26,11 +25,6 @@ static inline const void *of_get_mac_address(struct device_node *np) return NULL; } -static inline int of_get_nvmem_mac_address(struct device_node *np, void *addr) -{ - return -ENODEV; -} - static inline struct net_device *of_find_net_device_by_node(struct device_node *np) { return NULL; From patchwork Fri Nov 30 08:21:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10705947 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 6036F13BF for ; Fri, 30 Nov 2018 08:21:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 529352FBF1 for ; Fri, 30 Nov 2018 08:21:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46AC42FBFF; Fri, 30 Nov 2018 08:21:28 +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 E80C42FBF1 for ; Fri, 30 Nov 2018 08:21:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727243AbeK3T3y (ORCPT ); Fri, 30 Nov 2018 14:29:54 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37907 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727157AbeK3T3x (ORCPT ); Fri, 30 Nov 2018 14:29:53 -0500 Received: by mail-wm1-f68.google.com with SMTP id k198so4776315wmd.3 for ; Fri, 30 Nov 2018 00:21:22 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=f7gfNo0gVKcDfyj3+9h+7K8WG/3dMlnqMt9RiFsd5OU=; b=SMCP04mHX+HN8lYdExPwcBsPbSlvChP1SxdIPmKX1Ytvz+rpx1Z3k8xyxXiPGngx/I H89wzBI3hdnwTm1QfaKyi8iw2uOQLhtULTlj7Ado1sEL21QYE3mTpH+B9jJegADwpFby yANRPw/WRGlMgMO2r60UnuamjqMVnj5NyYWAPIuYhjgc9NIcYJhaoDmqq3QwMKT3ujnE rZ/wi2HNq5JuIlAlgQtUbU+CMSUsZRrVtXTh0xk/gW50jqOgsNd5OJWkbKgxMgG6vjIH aZTwe2oxlqmSTIMNFnf3DAnAQmdpEheCmYeZCPfnpTvFjyjhjRr3ZDSQlopIc7VYFTka 8FWg== 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:mime-version:content-transfer-encoding; bh=f7gfNo0gVKcDfyj3+9h+7K8WG/3dMlnqMt9RiFsd5OU=; b=HSaIYgcmT+3stLoSDnRq+Qn6xaOyZptiQCMP6bZC+wvubeR6ihHZgNjD3xDX/6g+7m gtzLbDuIPr/inRnz21dnU0UWFfaLq/JYCkyxI9ZU7YbGTm77ROyRybc5n9a631HRODuN xHPTRTfcZM7muxXuCji4dsg0Xy/u9ry4YldZxuO/cjUiSko116n+0cHDa1Jm8C4yoRPN GRM6vnn6o3PwUMGyTesPwN1cZivGGKQaK3zVhTHc2SzkccELN+/vPGD9i1CMrUOiHn06 F+2Mbz6AF4sJp93/RB0uZ3MI8/BqF5+moUV+Eg/pBiR4E9odVCGa8jx319F30XGEpvBC JKRw== X-Gm-Message-State: AA+aEWamJzVWd7KSug3+Ma/BnYaYgvptYEtAYp71PvMadUCwnV2YDkwA w8hH/oC736nw89PfqRvylvIfxQ== X-Google-Smtp-Source: AFSGD/VMhw3YbQrfCsu4V97PPFHUfcGIZvfrQo5y1/MLySEQGXyveI40+Q3kqQ5zsLdpXeB5yysX5Q== X-Received: by 2002:a7b:c095:: with SMTP id r21mr4650862wmh.118.1543566081898; Fri, 30 Nov 2018 00:21:21 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id x197sm6473374wmd.2.2018.11.30.00.21.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 00:21:21 -0800 (PST) From: Bartosz Golaszewski To: Grygorii Strashko , Nicolas Ferre , "David S . Miller" , Andrew Lunn , Florian Fainelli , Heiner Kallweit , Rob Herring , Frank Rowand , Sekhar Nori , Kevin Hilman Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-omap@vger.kernel.org, Bartosz Golaszewski Subject: [net-next][PATCH 4/4] net: davinci_emac: use nvmem_get_mac_address() Date: Fri, 30 Nov 2018 09:21:00 +0100 Message-Id: <20181130082100.6241-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181130082100.6241-1-brgl@bgdev.pl> References: <20181130082100.6241-1-brgl@bgdev.pl> MIME-Version: 1.0 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 All DaVinci boards still supported in board files now define nvmem cells containing the MAC address. We want to stop using the setup callback from at24 so the MAC address for those users will no longer be provided over platform data. If we didn't get a valid MAC in pdata, try nvmem before resorting to a random MAC. Signed-off-by: Bartosz Golaszewski --- drivers/net/ethernet/ti/davinci_emac.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c index 9153db120352..840820402cd0 100644 --- a/drivers/net/ethernet/ti/davinci_emac.c +++ b/drivers/net/ethernet/ti/davinci_emac.c @@ -1912,11 +1912,15 @@ static int davinci_emac_probe(struct platform_device *pdev) ether_addr_copy(ndev->dev_addr, priv->mac_addr); if (!is_valid_ether_addr(priv->mac_addr)) { - /* Use random MAC if none passed */ - eth_hw_addr_random(ndev); - memcpy(priv->mac_addr, ndev->dev_addr, ndev->addr_len); - dev_warn(&pdev->dev, "using random MAC addr: %pM\n", - priv->mac_addr); + /* Try nvmem if MAC wasn't passed over pdata or DT. */ + rc = nvmem_get_mac_address(&pdev->dev, priv->mac_addr); + if (rc) { + /* Use random MAC if still none obtained. */ + eth_hw_addr_random(ndev); + memcpy(priv->mac_addr, ndev->dev_addr, ndev->addr_len); + dev_warn(&pdev->dev, "using random MAC addr: %pM\n", + priv->mac_addr); + } } ndev->netdev_ops = &emac_netdev_ops;