aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Green <andy@warmcat.com>2011-03-24 21:27:38 +0000
committerNicolas Pitre <nicolas.pitre@linaro.org>2011-03-27 22:06:33 -0400
commit0603fc25db7d77ae7acd6066aa2e913398ed0e52 (patch)
tree3811334246999954209422a769dfc7905519419f
parent1da46fc5bbdbaba801f66e8419d3195924e1a5f3 (diff)
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> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Nicolas Pitre <nicolas.pitre@linaro.org>
-rw-r--r--arch/arm/mach-omap2/board-omap4panda.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/arch/arm/mach-omap2/board-omap4panda.c b/arch/arm/mach-omap2/board-omap4panda.c
index f3a7b101191..953f7593cc7 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>
@@ -714,6 +717,90 @@ void omap4_panda_display_init(void)
omap_display_init(&omap4_panda_dss_data);
}
+/*
+ * 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,
+};
+
static void __init omap4_panda_init(void)
{
int package = OMAP_PACKAGE_CBS;
@@ -725,6 +812,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);