All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, gregkh@linuxfoundation.org,
	rafael@kernel.org, andrew@lunn.ch, hkallweit1@gmail.com,
	linux@armlinux.org.uk, robh+dt@kernel.org,
	frowand.list@gmail.com, heikki.krogerus@linux.intel.com,
	devicetree@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 3/4] device property: add a helper for loading netdev->dev_addr
Date: Tue,  5 Oct 2021 08:53:20 -0700	[thread overview]
Message-ID: <20211005155321.2966828-4-kuba@kernel.org> (raw)
In-Reply-To: <20211005155321.2966828-1-kuba@kernel.org>

Commit 406f42fa0d3c ("net-next: When a bond have a massive amount
of VLANs...") introduced a rbtree for faster Ethernet address look
up. To maintain netdev->dev_addr in this tree we need to make all
the writes to it got through appropriate helpers.

There is a handful of drivers which pass netdev->dev_addr as
the destination buffer to device_get_mac_address(). Add a helper
which takes a dev pointer instead, so it can call an appropriate
helper.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 drivers/base/property.c  | 20 ++++++++++++++++++++
 include/linux/property.h |  2 ++
 2 files changed, 22 insertions(+)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 453918eb7390..1c8d4676addc 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -997,6 +997,26 @@ void *device_get_mac_address(struct device *dev, char *addr, int alen)
 }
 EXPORT_SYMBOL(device_get_mac_address);
 
+/**
+ * device_get_ethdev_addr - Set netdev's MAC address from a given device
+ * @dev:	Pointer to the device
+ * @netdev:	Pointer to netdev to write the address to
+ *
+ * Wrapper around device_get_mac_address() which writes the address
+ * directly to netdev->dev_addr.
+ */
+void *device_get_ethdev_addr(struct device *dev, struct net_device *netdev)
+{
+	u8 addr[ETH_ALEN];
+	void *ret;
+
+	ret = device_get_mac_address(dev, addr, ETH_ALEN);
+	if (ret)
+		eth_hw_addr_set(netdev, addr);
+	return ret;
+}
+EXPORT_SYMBOL(device_get_ethdev_addr);
+
 /**
  * fwnode_irq_get - Get IRQ directly from a fwnode
  * @fwnode:	Pointer to the firmware node
diff --git a/include/linux/property.h b/include/linux/property.h
index 357513a977e5..24dc4d2b9dbd 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -15,6 +15,7 @@
 #include <linux/types.h>
 
 struct device;
+struct net_device;
 
 enum dev_prop_type {
 	DEV_PROP_U8,
@@ -390,6 +391,7 @@ const void *device_get_match_data(struct device *dev);
 int device_get_phy_mode(struct device *dev);
 
 void *device_get_mac_address(struct device *dev, char *addr, int alen);
+void *device_get_ethdev_addr(struct device *dev, struct net_device *netdev);
 
 int fwnode_get_phy_mode(struct fwnode_handle *fwnode);
 void *fwnode_get_mac_address(struct fwnode_handle *fwnode,
-- 
2.31.1


  parent reply	other threads:[~2021-10-05 15:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-05 15:53 [PATCH net-next 0/4] net: add a helpers for loading netdev->dev_addr from FW Jakub Kicinski
2021-10-05 15:53 ` [PATCH net-next 1/4] of: net: add a helper for loading netdev->dev_addr Jakub Kicinski
2021-10-05 16:15   ` Rob Herring
2021-10-05 16:29     ` Jakub Kicinski
2021-10-05 16:39       ` Rob Herring
2021-10-05 16:54         ` Jakub Kicinski
2021-10-05 15:53 ` [PATCH net-next 2/4] ethernet: use of_get_ethdev_address() Jakub Kicinski
2021-10-05 15:53 ` Jakub Kicinski [this message]
2021-10-05 15:57   ` [PATCH net-next 3/4] device property: add a helper for loading netdev->dev_addr Greg KH
2021-10-06  7:43   ` Heikki Krogerus
2021-10-06 12:59     ` Jakub Kicinski
2021-10-05 15:53 ` [PATCH net-next 4/4] ethernet: use device_get_ethdev_addr() Jakub Kicinski

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=20211005155321.2966828-4-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=hkallweit1@gmail.com \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=rafael@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.