All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Green <andy.green@linaro.org>
To: linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Cc: nicolas.pitre@linaro.org, s-jan@ti.com, arnd@arndb.de,
	patches@linaro.org, tony@atomide.com, rostedt@goodmis.org
Subject: [PATCH 2/3] OMAP2+ devices add mac address allocation register api
Date: Fri, 29 Jun 2012 13:55:19 +0800	[thread overview]
Message-ID: <20120629055516.11091.82899.stgit@build.warmcat.com> (raw)
In-Reply-To: <20120629054404.11091.31289.stgit@build.warmcat.com>

From: Andy Green <andy@warmcat.com>

This exposes a new API in devices.c that lets a board register
a list of device paths representing network devices that have
no arrangements for their MAC address to be set by the board.

It watches network device registrations via a notifier and
gives the devices requiring them a synthetic - but constant for
a given board - MAC address immediately.

This approach is compatible with devices with asynchronous
probe such as the USB-based Etherent PHY and SDIO-based
wlan module found on PandaBoard / ES.

It has also been tested on PandaBoard 5 successfully but that
support is not part of this series.

Signed-off-by: Andy Green <andy.green@linaro.org>
---
 arch/arm/mach-omap2/common.h  |    2 +
 arch/arm/mach-omap2/devices.c |   89 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)

diff --git a/arch/arm/mach-omap2/common.h b/arch/arm/mach-omap2/common.h
index 5d99c1b..ae4d8a9 100644
--- a/arch/arm/mach-omap2/common.h
+++ b/arch/arm/mach-omap2/common.h
@@ -116,6 +116,8 @@ static inline int omap_mux_late_init(void)
 #endif
 
 extern void omap2_init_common_infrastructure(void);
+extern int omap_register_mac_device_fixup_paths(const char * const *paths,
+								    int count);
 
 extern struct sys_timer omap2_timer;
 extern struct sys_timer omap3_timer;
diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
index 91ef6699..d0a3d2d 100644
--- a/arch/arm/mach-omap2/devices.c
+++ b/arch/arm/mach-omap2/devices.c
@@ -18,12 +18,15 @@
 #include <linux/slab.h>
 #include <linux/of.h>
 #include <linux/platform_data/omap4-keypad.h>
+#include <linux/netdevice.h>
+#include <linux/if_ether.h>
 
 #include <mach/hardware.h>
 #include <mach/irqs.h>
 #include <asm/mach-types.h>
 #include <asm/mach/map.h>
 #include <asm/pmu.h>
+#include <mach/id.h>
 
 #include "iomap.h"
 #include <plat/board.h>
@@ -39,6 +42,9 @@
 #define L3_MODULES_MAX_LEN 12
 #define L3_MODULES 3
 
+static const char * const *mac_device_fixup_paths;
+int count_mac_device_fixup_paths;
+
 static int __init omap3_l3_init(void)
 {
 	struct omap_hwmod *oh;
@@ -627,6 +633,89 @@ static void omap_init_vout(void)
 static inline void omap_init_vout(void) {}
 #endif
 
+static int omap_device_path_need_mac(struct device *dev)
+{
+	const char **try = (const char **)mac_device_fixup_paths;
+	const char *path;
+	int count = count_mac_device_fixup_paths;
+	const char *p;
+	int len;
+	struct device *devn;
+
+	while (count--) {
+
+		p = *try + strlen(*try);
+		devn = dev;
+
+		while (devn) {
+
+			path = dev_name(devn);
+			len = strlen(path);
+
+			if ((p - *try) < len) {
+				devn = NULL;
+				continue;
+			}
+
+			p -= len;
+
+			if (strncmp(path, p, len)) {
+				devn = NULL;
+				continue;
+			}
+
+			devn = devn->parent;
+			if (p == *try)
+				return count;
+
+			if (devn != NULL && (p - *try) < 2)
+				devn = NULL;
+
+			p--;
+			if (devn != NULL && *p != '/')
+				devn = NULL;
+		}
+
+		try++;
+	}
+
+	return -ENOENT;
+}
+
+static int omap_panda_netdev_event(struct notifier_block *this,
+						unsigned long event, void *ptr)
+{
+	struct net_device *dev = ptr;
+	struct sockaddr sa;
+	int n;
+
+	if (event != NETDEV_REGISTER)
+		return NOTIFY_DONE;
+
+	n = omap_device_path_need_mac(dev->dev.parent);
+	if (n < 0)
+		return NOTIFY_DONE;
+
+	sa.sa_family = dev->type;
+	omap2_die_id_to_ethernet_mac(sa.sa_data, n);
+	dev->netdev_ops->ndo_set_mac_address(dev, &sa);
+
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block omap_panda_netdev_notifier = {
+	.notifier_call = omap_panda_netdev_event,
+	.priority = 1,
+};
+
+int omap_register_mac_device_fixup_paths(const char * const *paths, int count)
+{
+	mac_device_fixup_paths = paths;
+	count_mac_device_fixup_paths = count;
+
+	return register_netdevice_notifier(&omap_panda_netdev_notifier);
+}
+
 /*-------------------------------------------------------------------------*/
 
 static int __init omap2_init_devices(void)


WARNING: multiple messages have this Message-ID (diff)
From: andy.green@linaro.org (Andy Green)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/3] OMAP2+ devices add mac address allocation register api
Date: Fri, 29 Jun 2012 13:55:19 +0800	[thread overview]
Message-ID: <20120629055516.11091.82899.stgit@build.warmcat.com> (raw)
In-Reply-To: <20120629054404.11091.31289.stgit@build.warmcat.com>

From: Andy Green <andy@warmcat.com>

This exposes a new API in devices.c that lets a board register
a list of device paths representing network devices that have
no arrangements for their MAC address to be set by the board.

It watches network device registrations via a notifier and
gives the devices requiring them a synthetic - but constant for
a given board - MAC address immediately.

This approach is compatible with devices with asynchronous
probe such as the USB-based Etherent PHY and SDIO-based
wlan module found on PandaBoard / ES.

It has also been tested on PandaBoard 5 successfully but that
support is not part of this series.

Signed-off-by: Andy Green <andy.green@linaro.org>
---
 arch/arm/mach-omap2/common.h  |    2 +
 arch/arm/mach-omap2/devices.c |   89 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)

diff --git a/arch/arm/mach-omap2/common.h b/arch/arm/mach-omap2/common.h
index 5d99c1b..ae4d8a9 100644
--- a/arch/arm/mach-omap2/common.h
+++ b/arch/arm/mach-omap2/common.h
@@ -116,6 +116,8 @@ static inline int omap_mux_late_init(void)
 #endif
 
 extern void omap2_init_common_infrastructure(void);
+extern int omap_register_mac_device_fixup_paths(const char * const *paths,
+								    int count);
 
 extern struct sys_timer omap2_timer;
 extern struct sys_timer omap3_timer;
diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
index 91ef6699..d0a3d2d 100644
--- a/arch/arm/mach-omap2/devices.c
+++ b/arch/arm/mach-omap2/devices.c
@@ -18,12 +18,15 @@
 #include <linux/slab.h>
 #include <linux/of.h>
 #include <linux/platform_data/omap4-keypad.h>
+#include <linux/netdevice.h>
+#include <linux/if_ether.h>
 
 #include <mach/hardware.h>
 #include <mach/irqs.h>
 #include <asm/mach-types.h>
 #include <asm/mach/map.h>
 #include <asm/pmu.h>
+#include <mach/id.h>
 
 #include "iomap.h"
 #include <plat/board.h>
@@ -39,6 +42,9 @@
 #define L3_MODULES_MAX_LEN 12
 #define L3_MODULES 3
 
+static const char * const *mac_device_fixup_paths;
+int count_mac_device_fixup_paths;
+
 static int __init omap3_l3_init(void)
 {
 	struct omap_hwmod *oh;
@@ -627,6 +633,89 @@ static void omap_init_vout(void)
 static inline void omap_init_vout(void) {}
 #endif
 
+static int omap_device_path_need_mac(struct device *dev)
+{
+	const char **try = (const char **)mac_device_fixup_paths;
+	const char *path;
+	int count = count_mac_device_fixup_paths;
+	const char *p;
+	int len;
+	struct device *devn;
+
+	while (count--) {
+
+		p = *try + strlen(*try);
+		devn = dev;
+
+		while (devn) {
+
+			path = dev_name(devn);
+			len = strlen(path);
+
+			if ((p - *try) < len) {
+				devn = NULL;
+				continue;
+			}
+
+			p -= len;
+
+			if (strncmp(path, p, len)) {
+				devn = NULL;
+				continue;
+			}
+
+			devn = devn->parent;
+			if (p == *try)
+				return count;
+
+			if (devn != NULL && (p - *try) < 2)
+				devn = NULL;
+
+			p--;
+			if (devn != NULL && *p != '/')
+				devn = NULL;
+		}
+
+		try++;
+	}
+
+	return -ENOENT;
+}
+
+static int omap_panda_netdev_event(struct notifier_block *this,
+						unsigned long event, void *ptr)
+{
+	struct net_device *dev = ptr;
+	struct sockaddr sa;
+	int n;
+
+	if (event != NETDEV_REGISTER)
+		return NOTIFY_DONE;
+
+	n = omap_device_path_need_mac(dev->dev.parent);
+	if (n < 0)
+		return NOTIFY_DONE;
+
+	sa.sa_family = dev->type;
+	omap2_die_id_to_ethernet_mac(sa.sa_data, n);
+	dev->netdev_ops->ndo_set_mac_address(dev, &sa);
+
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block omap_panda_netdev_notifier = {
+	.notifier_call = omap_panda_netdev_event,
+	.priority = 1,
+};
+
+int omap_register_mac_device_fixup_paths(const char * const *paths, int count)
+{
+	mac_device_fixup_paths = paths;
+	count_mac_device_fixup_paths = count;
+
+	return register_netdevice_notifier(&omap_panda_netdev_notifier);
+}
+
 /*-------------------------------------------------------------------------*/
 
 static int __init omap2_init_devices(void)

  parent reply	other threads:[~2012-06-29  5:55 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-29  5:55 [PATCH 0/3] Add ability to set defaultless network device MAC addresses to deterministic computed locally administered values Andy Green
2012-06-29  5:55 ` Andy Green
2012-06-29  5:55 ` [PATCH 1/3] OMAP2+: add cpu id register to MAC address helper Andy Green
2012-06-29  5:55   ` Andy Green
2012-06-29  9:05   ` Tony Lindgren
2012-06-29  9:05     ` Tony Lindgren
2012-06-29  9:13     ` Andy Green
2012-06-29  9:13       ` Andy Green
2012-06-29  5:55 ` Andy Green [this message]
2012-06-29  5:55   ` [PATCH 2/3] OMAP2+ devices add mac address allocation register api Andy Green
2012-06-29  8:51   ` Arnd Bergmann
2012-06-29  8:51     ` Arnd Bergmann
2012-06-29  9:03     ` Andy Green
2012-06-29  9:03       ` Andy Green
2012-06-29  9:40   ` Tony Lindgren
2012-06-29  9:40     ` Tony Lindgren
2012-06-29 10:07     ` Andy Green
2012-06-29 10:07       ` Andy Green
2012-06-29 12:03       ` Tony Lindgren
2012-06-29 12:03         ` Tony Lindgren
2012-06-29 13:45         ` Arnd Bergmann
2012-06-29 13:45           ` Arnd Bergmann
2012-06-29 13:55           ` Tony Lindgren
2012-06-29 13:55             ` Tony Lindgren
2012-06-29 13:59             ` Andy Green
2012-06-29 13:59               ` Andy Green
2012-06-29 14:33             ` Arnd Bergmann
2012-06-29 14:33               ` Arnd Bergmann
2012-06-29 14:52               ` Tony Lindgren
2012-06-29 14:52                 ` Tony Lindgren
2012-06-29 15:05                 ` Arnd Bergmann
2012-06-29 15:05                   ` Arnd Bergmann
2012-07-01  8:58                   ` Tony Lindgren
2012-07-01  8:58                     ` Tony Lindgren
2012-07-02  7:15                     ` Arnd Bergmann
2012-07-02  7:15                       ` Arnd Bergmann
2012-07-02 10:51                       ` Tony Lindgren
2012-07-02 10:51                         ` Tony Lindgren
2012-06-29 14:03           ` Andy Green
2012-06-29 14:03             ` Andy Green
2012-06-29 14:38             ` Arnd Bergmann
2012-06-29 14:38               ` Arnd Bergmann
2012-06-29  5:55 ` [PATCH 3/3] OMAP4 PANDA register ethernet and wlan for automatic mac allocation Andy Green
2012-06-29  5:55   ` Andy Green
2012-06-29 11:55   ` Tony Lindgren
2012-06-29 11:55     ` Tony Lindgren
2012-06-29  8:50 ` [PATCH 0/3] Add ability to set defaultless network device MAC addresses to deterministic computed locally administered values Arnd Bergmann
2012-06-29  8:50   ` Arnd Bergmann

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=20120629055516.11091.82899.stgit@build.warmcat.com \
    --to=andy.green@linaro.org \
    --cc=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=nicolas.pitre@linaro.org \
    --cc=patches@linaro.org \
    --cc=rostedt@goodmis.org \
    --cc=s-jan@ti.com \
    --cc=tony@atomide.com \
    /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.