From patchwork Wed Jul 18 16:10:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10532773 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 40D13600F4 for ; Wed, 18 Jul 2018 16:10:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3151425EF7 for ; Wed, 18 Jul 2018 16:10:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 259522996B; Wed, 18 Jul 2018 16:10: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=-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 B9BC325EF7 for ; Wed, 18 Jul 2018 16:10:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731601AbeGRQtZ (ORCPT ); Wed, 18 Jul 2018 12:49:25 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:56126 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731576AbeGRQtY (ORCPT ); Wed, 18 Jul 2018 12:49:24 -0400 Received: by mail-wm0-f68.google.com with SMTP id f21-v6so3338375wmc.5 for ; Wed, 18 Jul 2018 09:10:48 -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=UI9KTymoEQZqQnq+XDW6aBlMZfkVrCAcmaUDPOUsmDI=; b=pguzGXezdMo+nCfj61cb9cSQDJqpYDOA2Gm52xVOTudW90q76PH+oziuivmWzBxLZE wtA1jQ6Bk6uQRqzgzsCvt6VJc+tYlIgj2iihBaSg+0+LI9R/DlcymyHnghikJdhwETRw xR7fsF4k8WOglmZibZCTOzoTfu2sV9GGzcFqznTMhcngd2LKH248xBwGdMx6i5qEa3EV jcCVbwn7C5iOzkxffP2dGUHTzarnYExs7HWv8xVL221UYVL53bQDeTcC0RLOHgbrdrcd acAYPAWGHFQv5Dg0u4CNkmnHaHE9PiL8OdGnxH/JT8/LKlPPsyN30iMUG4uANiumViy3 Ub9g== 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=UI9KTymoEQZqQnq+XDW6aBlMZfkVrCAcmaUDPOUsmDI=; b=bZMceFLvMowSqsRT59eCL1bF5Ru7YmvWBHsxlmsVRlcZOz0t/iPf1VruYLBxxZfv5s fpZOYdacdsZ0YEXl/zbgE3/hMioxyszrLA+jpPdqVILvA2aQPnucRUOLPrAdjNAetnsC UAZxyNknv1WBFjRVAKBd76qxsJnvlgkNXOLxnP7Du6WMx29fHEFuA0FuBbxT3OPrHzmS o51SOWke/eyQjnpp+KN8EyaoWkyjFHdqN27HwfDIJMhviH+2O05mOAJNquz0v2Xb3quv 841xwi3vQUkum59EA6YwXWI7RpS3h4TOuobsWEz5LVMcCtcfxkK5LJDC20eEmVSOBr9t nUZA== X-Gm-Message-State: AOUpUlFMhy0ZA/2PEDoJQbhn1Z+vHTgOfZa3+ctdm/EX7T3UaJHCH3NM zHhG48HARYVTl0vATuWjMza4Cw== X-Google-Smtp-Source: AAOMgpcwQPB1DFnur4NqIP4uqwTLePGwa5l7iBSUGa11B1GdVBq0tO/YH/N5apraJ12RGysmcl6whw== X-Received: by 2002:a1c:838a:: with SMTP id f132-v6mr2074786wmd.127.1531930247866; Wed, 18 Jul 2018 09:10:47 -0700 (PDT) Received: from brgl-bgdev.home ([2a01:cb1d:af:5b00:e837:b8d5:48c1:571b]) by smtp.gmail.com with ESMTPSA id v185-v6sm2847803wme.30.2018.07.18.09.10.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 09:10:47 -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 4/5] net: add support for nvmem to eth_platform_get_mac_address() Date: Wed, 18 Jul 2018 18:10:34 +0200 Message-Id: <20180718161035.7005-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180718161035.7005-1-brgl@bgdev.pl> References: <20180718161035.7005-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 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index 6b64586fd2af..adf5bd03851f 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -530,7 +531,10 @@ int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) struct device_node *dp = dev_is_pci(dev) ? pci_device_to_OF_node(to_pci_dev(dev)) : dev->of_node; const unsigned char *addr = NULL; + unsigned char addrbuf[ETH_ALEN]; + struct nvmem_cell *nvmem; const char *from = NULL; + size_t alen; if (dp) { addr = of_get_mac_address(dp); @@ -544,6 +548,31 @@ int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) from = "arch callback"; } + if (!addr) { + nvmem = nvmem_cell_get(dev, "mac-address"); + if (IS_ERR(nvmem) && PTR_ERR(nvmem) == -EPROBE_DEFER) + /* We may have a lookup registered for MAC address but + * the corresponding nvmem provider hasn't been + * registered yet. + */ + return -EPROBE_DEFER; + + if (!IS_ERR(nvmem)) { + addr = nvmem_cell_read(nvmem, &alen); + if (!IS_ERR(addr)) { + from = "nvmem"; + /* Don't use ether_addr_copy() in case we + * didn't get the right size. + */ + memcpy(addrbuf, addr, alen); + kfree(addr); + addr = addrbuf; + } + + nvmem_cell_put(nvmem); + } + } + if (!addr || !is_valid_ether_addr(addr)) return -ENODEV;