linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: hemahk@ti.com (Hema Kalliguddi)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 2/2] OMAP2+: PANDA: Fix up random or missing MAC addresses for eth0 and wlan0
Date: Fri, 25 Mar 2011 13:09:38 +0530	[thread overview]
Message-ID: <78b7faad4cdc37c6b507c008fde18ef3@mail.gmail.com> (raw)
In-Reply-To: <20110324212737.14936.21228.stgit@otae.warmcat.com>

Hi,

one Minor comment.

>-----Original Message-----
From: linux-omap-owner@vger.kernel.org
>[mailto:linux-omap-owner at vger.kernel.org] On Behalf Of Andy Green
>Sent: Friday, March 25, 2011 2:58 AM
>To: linux-arm-kernel at lists.infradead.org; linux-omap at vger.kernel.org
>Cc: patches at linaro.org; nicolas.pitre at linaro.org;
>arnd at arndb.de; x0132446 at ti.com; s-jan at ti.com;
>tony at atomide.com; Alan Cox; Andy Green
>Subject: [RFC PATCH 2/2] OMAP2+: PANDA: Fix up random or
>missing MAC addresses for eth0 and wlan0
>
>This patch registers a network device notifier callback to set the mac
>addresses for the onboard network assets of Panda correctly,
>despite the
>drivers involved have used a random or all-zeros MAC address.
>
>The technique was suggested by Alan Cox on lkml.
>
>It works by device path so it corrects the MAC addresses even if the
>drivers are in modules loaded in an order that changes their interface
>name from usual (eg, the onboard module might be "wlan1" if there is a
>USB wireless stick plugged in and its module is inserted first.)
>
>Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
>Signed-off-by: Andy Green <andy.green@linaro.org>
>---
>
> arch/arm/mach-omap2/board-omap4panda.c |   91
>++++++++++++++++++++++++++++++++
> 1 files changed, 91 insertions(+), 0 deletions(-)
>
>diff --git a/arch/arm/mach-omap2/board-omap4panda.c
>b/arch/arm/mach-omap2/board-omap4panda.c
>index 80b8860..0b92873 100644
>--- a/arch/arm/mach-omap2/board-omap4panda.c
>+++ b/arch/arm/mach-omap2/board-omap4panda.c
>@@ -28,9 +28,12 @@
> #include <linux/regulator/machine.h>
> #include <linux/regulator/fixed.h>
> #include <linux/wl12xx.h>
>+#include <linux/netdevice.h>
>+#include <linux/if_ether.h>
>
> #include <mach/hardware.h>
> #include <mach/omap4-common.h>
>+#include <mach/id.h>
> #include <asm/mach-types.h>
> #include <asm/mach/arch.h>
> #include <asm/mach/map.h>
>@@ -506,6 +509,92 @@ static inline void board_serial_init(void)
> }
> #endif
>
>+/*
>+ * These device paths represent the onboard USB <-> Ethernet
>bridge, and
>+ * the WLAN module on Panda, both of which need their random
>or all-zeros
>+ * mac address replacing with a per-cpu stable generated one
>+ */
>+
>+static const char * const panda_fixup_mac_device_paths[] = {
>+	"usb1/1-1/1-1.1/1-1.1:1.0",
>+	"mmc1:0001:2",
>+};
>+
>+static int panda_device_path_need_mac(struct device *dev)
>+{
>+	const char **try = panda_fixup_mac_device_paths;
>+	const char *path;
>+	int count = ARRAY_SIZE(panda_fixup_mac_device_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 = panda_device_path_need_mac(dev->dev.parent);
>+	if (n >= 0) {
>+		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,
>+};
>+
>+

One extra blank line not needed.

Regards,
Hema

> static void __init omap4_panda_init(void)
> {
> 	int package = OMAP_PACKAGE_CBS;
>@@ -517,6 +606,8 @@ static void __init omap4_panda_init(void)
> 	if (wl12xx_set_platform_data(&omap_panda_wlan_data))
> 		pr_err("error setting wl12xx data\n");
>
>+	register_netdevice_notifier(&omap_panda_netdev_notifier);
>+
> 	omap4_panda_i2c_init();
> 	platform_add_devices(panda_devices, ARRAY_SIZE(panda_devices));
> 	platform_device_register(&omap_vwlan_device);
>
>--
>To unsubscribe from this list: send the line "unsubscribe
>linux-omap" in
>the body of a message to majordomo at vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

  reply	other threads:[~2011-03-25  7:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-24 21:27 [RFC PATCH 0/2] OMAP2+: PANDA: Provide unique-ish MAC addresses for Ethernet and WLAN interfaces Andy Green
2011-03-24 21:27 ` [RFC PATCH 1/2] OMAP2+: add cpu id register to MAC address helper Andy Green
2011-03-25 11:49   ` Arnd Bergmann
2011-03-25 12:08     ` Andy Green
2011-03-25 13:24       ` Arnd Bergmann
2011-03-25 13:34         ` Andy Green
2011-03-25 14:50           ` Arnd Bergmann
2011-03-25 15:00             ` Andy Green
2011-03-24 21:27 ` [RFC PATCH 2/2] OMAP2+: PANDA: Fix up random or missing MAC addresses for eth0 and wlan0 Andy Green
2011-03-25  7:39   ` Hema Kalliguddi [this message]
2011-03-25 20:13     ` Jason Kridner
2011-03-25 20:20       ` Arnd Bergmann
2011-03-25 20:23       ` Nicolas Pitre
2011-03-28 12:54         ` Jason Kridner
2011-03-25 20:30       ` Andy Green
2011-03-25 11:39   ` Arnd Bergmann
2012-06-28 14:18 ` [RFC PATCH 0/2] OMAP2+: PANDA: Provide unique-ish MAC addresses for Ethernet and WLAN interfaces Arnd Bergmann
2012-06-28 14:45   ` Steven Rostedt
2012-06-28 14:49     ` "Andy Green (林安廸)"

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=78b7faad4cdc37c6b507c008fde18ef3@mail.gmail.com \
    --to=hemahk@ti.com \
    --cc=linux-arm-kernel@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;
as well as URLs for NNTP newsgroup(s).