linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Walle <michael@walle.cc>
To: netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Rob Herring <robh+dt@kernel.org>, Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	Frank Rowand <frowand.list@gmail.com>,
	Michael Walle <michael@walle.cc>
Subject: [PATCH net-next 3/3] net: implement nvmem-mac-address-offset DT property
Date: Wed, 14 Apr 2021 17:26:57 +0200	[thread overview]
Message-ID: <20210414152657.12097-4-michael@walle.cc> (raw)
In-Reply-To: <20210414152657.12097-1-michael@walle.cc>

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 <michael@walle.cc>
---
 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);
-- 
2.20.1


      parent reply	other threads:[~2021-04-14 15:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-14 15:26 [PATCH net-next 0/3] net: add support for an offset of a nvmem provided MAC address Michael Walle
2021-04-14 15:26 ` [PATCH net-next 1/3] dt-bindings: net: add nvmem-mac-address-offset property Michael Walle
2021-04-14 15:43   ` Andrew Lunn
2021-04-15 21:59     ` Rob Herring
2021-04-15 22:27       ` Michael Walle
2021-05-12 15:27         ` Michael Walle
2021-04-15 23:45       ` Florian Fainelli
2021-04-14 15:26 ` [PATCH net-next 2/3] net: add helper eth_addr_add() Michael Walle
2021-04-14 15:26 ` Michael Walle [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210414152657.12097-4-michael@walle.cc \
    --to=michael@walle.cc \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).