From patchwork Thu Mar 24 21:27:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Green X-Patchwork-Id: 777 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:45:43 -0000 Delivered-To: patches@linaro.org Received: by 10.42.161.68 with SMTP id s4cs135110icx; Thu, 24 Mar 2011 14:27:52 -0700 (PDT) Received: by 10.216.58.207 with SMTP id q57mr7511108wec.63.1301002071298; Thu, 24 Mar 2011 14:27:51 -0700 (PDT) Received: from mail-wy0-f178.google.com (mail-wy0-f178.google.com [74.125.82.178]) by mx.google.com with ESMTPS id a2si487168wer.74.2011.03.24.14.27.49 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 24 Mar 2011 14:27:50 -0700 (PDT) Received-SPF: pass (google.com: domain of andy.warmcat.com@googlemail.com designates 74.125.82.178 as permitted sender) client-ip=74.125.82.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of andy.warmcat.com@googlemail.com designates 74.125.82.178 as permitted sender) smtp.mail=andy.warmcat.com@googlemail.com; dkim=pass (test mode) header.i=@googlemail.com Received: by wyj26 with SMTP id 26so395997wyj.37 for ; Thu, 24 Mar 2011 14:27:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:sender:from:subject:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version:content-type :content-transfer-encoding; bh=4db2vWdlRhJrBPRddw7e+wLQGnj7SFLJJA6wapWLaRw=; b=rD1sBcobHVxwhujYavCBJZNWDGmWSlvsYV4Og9mT1rRH40GQhQpV15Az1xm+r9sIcu CaRpGGWnzDTaBYmJJNbY7axr/qxxb9Lxs2Uw4wun7cXT41YZa+i2dOMBQvwbMG9K51Rm 3ZCUXw2Dl+rPREZnbYSw0f46qdZO3t7DwjVTc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=sender:from:subject:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding; b=jnor4TSGVnkCqjbafPiDfklG9QV4RhDtAu2tDAfeSRit1zV03vQeZSDnzciXWC3JXJ BxVJNLs1dIPCh7JQB+2qKDerJHL9LuOVpfygTBC3pYjgfSjAVG0cVy+9F6aTFYUsNDxN Q4YJaDNp7KBEI9bGZw8EK2qquBJYiogvjvQDk= Received: by 10.216.141.72 with SMTP id f50mr7844590wej.26.1301002060708; Thu, 24 Mar 2011 14:27:40 -0700 (PDT) Received: from otae.warmcat.com (s15404224.onlinehome-server.info [87.106.134.80]) by mx.google.com with ESMTPS id r80sm113834wei.39.2011.03.24.14.27.39 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 24 Mar 2011 14:27:40 -0700 (PDT) Sender: Andy Green From: Andy Green Subject: [RFC PATCH 2/2] OMAP2+: PANDA: Fix up random or missing MAC addresses for eth0 and wlan0 To: linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org Cc: patches@linaro.org, nicolas.pitre@linaro.org, arnd@arndb.de, x0132446@ti.com, s-jan@ti.com, tony@atomide.com, Alan Cox , Andy Green Date: Thu, 24 Mar 2011 21:27:38 +0000 Message-ID: <20110324212737.14936.21228.stgit@otae.warmcat.com> In-Reply-To: <20110324211451.14936.39750.stgit@otae.warmcat.com> References: <20110324211451.14936.39750.stgit@otae.warmcat.com> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 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 Signed-off-by: Andy Green Acked-by: Arnd Bergmann --- 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 #include #include +#include +#include #include #include +#include #include #include #include @@ -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, +}; + + 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);