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: 660571 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p2OLSKqB007914 for ; Thu, 24 Mar 2011 21:28:20 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757248Ab1CXV1z (ORCPT ); Thu, 24 Mar 2011 17:27:55 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:56562 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757235Ab1CXV1t (ORCPT ); Thu, 24 Mar 2011 17:27:49 -0400 Received: by mail-ww0-f44.google.com with SMTP id 36so456497wwa.1 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) 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 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 24 Mar 2011 21:28:20 +0000 (UTC) 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);