From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 4/5] net: Add of_register_ethaddr
Date: Tue, 21 May 2013 09:38:14 +0200 [thread overview]
Message-ID: <1369121895-11282-5-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1369121895-11282-1-git-send-email-s.hauer@pengutronix.de>
We already have a possibility to register a MAC address provider
based on a ethernet device id. This adds a similar functionality
for devices probed from devicetree. Code can register itself to
be a MAC address provider for a certain devicetree node.
This helps on i.MX to let the IIM unit provide a MAC address for
the FEC.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/net.h | 5 +++++
net/eth.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 61 insertions(+), 12 deletions(-)
diff --git a/include/net.h b/include/net.h
index bb6b8fa..610a6e6 100644
--- a/include/net.h
+++ b/include/net.h
@@ -76,8 +76,13 @@ int eth_rx(void); /* Check for received packets */
static inline void eth_register_ethaddr(int ethid, const char *ethaddr)
{
}
+static inline void of_eth_register_ethaddr(struct device_node *node,
+ const char *ethaddr)
+{
+}
#else
void eth_register_ethaddr(int ethid, const char *ethaddr);
+void of_eth_register_ethaddr(struct device_node *node, const char *ethaddr);
#endif
/*
* Ethernet header
diff --git a/net/eth.c b/net/eth.c
index 4646dd8..bea7b12 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -36,16 +36,34 @@ struct eth_ethaddr {
struct list_head list;
u8 ethaddr[6];
int ethid;
+ struct device_node *node;
};
static LIST_HEAD(ethaddr_list);
-static int eth_get_registered_ethaddr(int ethid, void *buf)
+static void register_preset_mac_address(struct eth_device *edev, const char *ethaddr)
+{
+ unsigned char ethaddr_str[sizeof("xx:xx:xx:xx:xx:xx")];
+
+ ethaddr_to_string(ethaddr, ethaddr_str);
+
+ if (is_valid_ether_addr(ethaddr)) {
+ dev_info(&edev->dev, "got preset MAC address: %s\n", ethaddr_str);
+ dev_set_param(&edev->dev, "ethaddr", ethaddr_str);
+ }
+}
+
+static int eth_get_registered_ethaddr(struct eth_device *edev, void *buf)
{
struct eth_ethaddr *addr;
+ struct device_node *node = NULL;
+
+ if (edev->parent)
+ node = edev->parent->device_node;
list_for_each_entry(addr, ðaddr_list, list) {
- if (addr->ethid == ethid) {
+ if ((node && node == addr->node) ||
+ addr->ethid == edev->dev.id) {
memcpy(buf, addr->ethaddr, 6);
return 0;
}
@@ -78,6 +96,38 @@ void eth_register_ethaddr(int ethid, const char *ethaddr)
list_add_tail(&addr->list, ðaddr_list);
}
+static struct eth_device *eth_get_by_node(struct device_node *node)
+{
+ struct eth_device *edev;
+
+ list_for_each_entry(edev, &netdev_list, list) {
+ if (!edev->parent)
+ continue;
+ if (!edev->parent->device_node)
+ continue;
+ if (edev->parent->device_node == node)
+ return edev;
+ }
+ return NULL;
+}
+
+void of_eth_register_ethaddr(struct device_node *node, const char *ethaddr)
+{
+ struct eth_ethaddr *addr;
+ struct eth_device *edev;
+
+ edev = eth_get_by_node(node);
+ if (edev) {
+ register_preset_mac_address(edev, ethaddr);
+ return;
+ }
+
+ addr = xzalloc(sizeof(*addr));
+ addr->node = node;
+ memcpy(addr->ethaddr, ethaddr, 6);
+ list_add_tail(&addr->list, ðaddr_list);
+}
+
void eth_set_current(struct eth_device *eth)
{
if (eth_current && eth_current->active) {
@@ -225,8 +275,7 @@ static int eth_set_ethaddr(struct device_d *dev, struct param_d *param, const ch
int eth_register(struct eth_device *edev)
{
- struct device_d *dev = &edev->dev;
- unsigned char ethaddr_str[20];
+ struct device_d *dev = &edev->dev;
unsigned char ethaddr[6];
int ret, found = 0;
@@ -254,7 +303,7 @@ int eth_register(struct eth_device *edev)
list_add_tail(&edev->list, &netdev_list);
- ret = eth_get_registered_ethaddr(dev->id, ethaddr);
+ ret = eth_get_registered_ethaddr(edev, ethaddr);
if (!ret)
found = 1;
@@ -264,13 +313,8 @@ int eth_register(struct eth_device *edev)
found = 1;
}
- if (found) {
- ethaddr_to_string(ethaddr, ethaddr_str);
- if (is_valid_ether_addr(ethaddr)) {
- dev_info(dev, "got preset MAC address: %s\n", ethaddr_str);
- dev_set_param(dev, "ethaddr", ethaddr_str);
- }
- }
+ if (found)
+ register_preset_mac_address(edev, ethaddr);
if (!eth_current)
eth_current = edev;
--
1.8.2.rc2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-05-21 7:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-21 7:38 [PATCH] misc oftree patches Sascha Hauer
2013-05-21 7:38 ` [PATCH 1/5] pinctrl: imx-iomux-v3: only register pinctrl when device node is available Sascha Hauer
2013-06-05 15:18 ` Lucas Stach
2013-06-05 20:33 ` Sascha Hauer
2013-05-21 7:38 ` [PATCH 2/5] spi: improve devicetree support Sascha Hauer
2013-05-21 7:38 ` [PATCH 3/5] mtd: dataflash: Add devicetree probing support Sascha Hauer
2013-05-21 7:38 ` Sascha Hauer [this message]
2013-05-21 7:38 ` [PATCH 5/5] net: fec: Add imx25 compatible property Sascha Hauer
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=1369121895-11282-5-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.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