From patchwork Wed Apr 14 15:26:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 12203183 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A911BC43460 for ; Wed, 14 Apr 2021 15:27:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E1C861164 for ; Wed, 14 Apr 2021 15:27:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232986AbhDNP1f (ORCPT ); Wed, 14 Apr 2021 11:27:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352136AbhDNP1a (ORCPT ); Wed, 14 Apr 2021 11:27:30 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [IPv6:2a01:4f8:151:8464::1:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E1C8C061574; Wed, 14 Apr 2021 08:27:08 -0700 (PDT) Received: from mwalle01.fritz.box (unknown [IPv6:2a02:810c:c200:2e91:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 7BD1522256; Wed, 14 Apr 2021 17:27:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1618414026; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ljBbstorYR1PhEMFBo4o7Tzx1N/BNduPatEctwY+WE8=; b=NEk7r0PK7md8vHykdrqqzaew64NqU5j3QhiLu867AIqJk0Q1cGlwOnSh4Re41gU7xw+5c1 WRbzirP7mFv8MwV7mrKxIhEgO6NF5vZZeWQJYD4bP3yf7eaqoCliMF0w8hW3Od5IXsHb0r Mvgm34J31vPmxWuWk4+uDRa7/L7ajMc= From: Michael Walle To: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "David S . Miller" , Jakub Kicinski , Rob Herring , Andrew Lunn , Heiner Kallweit , Russell King , Frank Rowand , Michael Walle Subject: [PATCH net-next 1/3] dt-bindings: net: add nvmem-mac-address-offset property Date: Wed, 14 Apr 2021 17:26:55 +0200 Message-Id: <20210414152657.12097-2-michael@walle.cc> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210414152657.12097-1-michael@walle.cc> References: <20210414152657.12097-1-michael@walle.cc> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org It is already possible to read the MAC address via a NVMEM provider. But there are boards, esp. with many ports, which only have a base MAC address stored. Thus we need to have a way to provide an offset per network device. Signed-off-by: Michael Walle --- .../devicetree/bindings/net/ethernet-controller.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/net/ethernet-controller.yaml b/Documentation/devicetree/bindings/net/ethernet-controller.yaml index e8f04687a3e0..1a8517b0e445 100644 --- a/Documentation/devicetree/bindings/net/ethernet-controller.yaml +++ b/Documentation/devicetree/bindings/net/ethernet-controller.yaml @@ -52,6 +52,12 @@ properties: nvmem-cell-names: const: mac-address + nvmem-mac-address-offset: + maxItems: 1 + description: + Specifies an offset which will be added to the MAC address when + fetched from a nvmem cell. + phy-connection-type: description: Specifies interface type between the Ethernet device and a physical From patchwork Wed Apr 14 15:26:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 12203179 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25F97C43460 for ; Wed, 14 Apr 2021 15:27:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0DA2D6100B for ; Wed, 14 Apr 2021 15:27:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352180AbhDNP1d (ORCPT ); Wed, 14 Apr 2021 11:27:33 -0400 Received: from ssl.serverraum.org ([176.9.125.105]:55319 "EHLO ssl.serverraum.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232986AbhDNP1a (ORCPT ); Wed, 14 Apr 2021 11:27:30 -0400 Received: from mwalle01.fritz.box (unknown [IPv6:2a02:810c:c200:2e91:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 3915522259; Wed, 14 Apr 2021 17:27:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1618414027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kAc6ABhNpdnJCipHDGNcvRdgD5/her0GkKHAGvSZOng=; b=bS1MJZhoLHWk9DbaawVJZhcQ/SwxDaX6O882z2I/dlhLMi/8uVPiHWIJhU3uvUpX1t/XDN gHVDOuYRYJFucZlBwLywpApmx4ToGXRYB+jVp7SHCc3cd/6hxmuBzMNpdgWA65eHehNG3H DjDNk/Y+yG+0Xu5VpDzaAk1Zkan+AZo= From: Michael Walle To: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "David S . Miller" , Jakub Kicinski , Rob Herring , Andrew Lunn , Heiner Kallweit , Russell King , Frank Rowand , Michael Walle Subject: [PATCH net-next 2/3] net: add helper eth_addr_add() Date: Wed, 14 Apr 2021 17:26:56 +0200 Message-Id: <20210414152657.12097-3-michael@walle.cc> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210414152657.12097-1-michael@walle.cc> References: <20210414152657.12097-1-michael@walle.cc> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Sometimes you need to add an offset to a base ethernet address. Add a helper for that. Signed-off-by: Michael Walle --- include/linux/etherdevice.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index 330345b1be54..6ec62c501d3f 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -466,6 +466,20 @@ static inline void eth_addr_inc(u8 *addr) u64_to_ether_addr(u, addr); } +/** + * eth_addr_add() - Add (or subtract) and offset to/from the given MAC address. + * + * @offset: Offset to add. + * @addr: Pointer to a six-byte array containing Ethernet address to increment. + */ +static inline void eth_addr_add(u8 *addr, long offset) +{ + u64 u = ether_addr_to_u64(addr); + + u += offset; + u64_to_ether_addr(u, addr); +} + /** * is_etherdev_addr - Tell if given Ethernet address belongs to the device. * @dev: Pointer to a device structure From patchwork Wed Apr 14 15:26:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 12203181 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6F9AC43462 for ; Wed, 14 Apr 2021 15:27:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9AD9161158 for ; Wed, 14 Apr 2021 15:27:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352221AbhDNP1g (ORCPT ); Wed, 14 Apr 2021 11:27:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352138AbhDNP1b (ORCPT ); Wed, 14 Apr 2021 11:27:31 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [IPv6:2a01:4f8:151:8464::1:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FFC1C061756; Wed, 14 Apr 2021 08:27:09 -0700 (PDT) Received: from mwalle01.fritz.box (unknown [IPv6:2a02:810c:c200:2e91:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id A848322260; Wed, 14 Apr 2021 17:27:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1618414027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yzD3ZqdGmr1DdLAfgBlMTWQ/ij/c36NrdB4QWYRCpIY=; b=ST5iJYYID4fuxydmgC4pxXXQKAk0J27jbpXkXw7zfCWbuWpeczLoDHs8lODtIP4RfyP4Zr bHYMp1Fp6/wrceuHNokQeTahaZJcIIOp0jizWye7QUvSqjwKwHC29jiJsXa0JDhtVTjMUU EQwKFBHnyHq36ihoRAqApPDyDPDCMho= From: Michael Walle To: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "David S . Miller" , Jakub Kicinski , Rob Herring , Andrew Lunn , Heiner Kallweit , Russell King , Frank Rowand , Michael Walle Subject: [PATCH net-next 3/3] net: implement nvmem-mac-address-offset DT property Date: Wed, 14 Apr 2021 17:26:57 +0200 Message-Id: <20210414152657.12097-4-michael@walle.cc> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210414152657.12097-1-michael@walle.cc> References: <20210414152657.12097-1-michael@walle.cc> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The MAC address fetched by an NVMEM provider might have an offset to it. Add the support for it in nvmem_get_mac_address(). Signed-off-by: Michael Walle --- drivers/of/of_net.c | 4 ++++ net/ethernet/eth.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c index dbac3a172a11..60c6048a823a 100644 --- a/drivers/of/of_net.c +++ b/drivers/of/of_net.c @@ -63,6 +63,7 @@ static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr) struct nvmem_cell *cell; const void *mac; size_t len; + u32 offset; int ret; /* Try lookup by device first, there might be a nvmem_cell_lookup @@ -92,6 +93,9 @@ static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr) memcpy(addr, mac, ETH_ALEN); kfree(mac); + if (!of_property_read_u32(np, "nvmem-mac-address-offset", &offset)) + eth_addr_add(addr, offset); + return 0; } diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index 9cce612e8976..fe5311f614fe 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -541,6 +541,7 @@ int nvmem_get_mac_address(struct device *dev, void *addrbuf) { struct nvmem_cell *cell; const void *mac; + u32 offset; size_t len; cell = nvmem_cell_get(dev, "mac-address"); @@ -561,6 +562,10 @@ int nvmem_get_mac_address(struct device *dev, void *addrbuf) ether_addr_copy(addrbuf, mac); kfree(mac); + if (!device_property_read_u32(dev, "nvmem-mac-address-offset", + &offset)) + eth_addr_add(addrbuf, offset); + return 0; } EXPORT_SYMBOL(nvmem_get_mac_address);