From patchwork Fri Jun 29 05:55:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: warmcat X-Patchwork-Id: 9694 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 89E7B23E01 for ; Fri, 29 Jun 2012 05:55:25 +0000 (UTC) Received: from mail-ob0-f180.google.com (mail-ob0-f180.google.com [209.85.214.180]) by fiordland.canonical.com (Postfix) with ESMTP id 4E0A6A18135 for ; Fri, 29 Jun 2012 05:55:25 +0000 (UTC) Received: by mail-ob0-f180.google.com with SMTP id uo19so4611384obb.11 for ; Thu, 28 Jun 2012 22:55:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:subject:to :from:cc:date:message-id:in-reply-to:references:user-agent :mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=JHvmp4o3dnrdmTCfNvcsB8BEK26QRaL/CiA3yhwWi2w=; b=Foy3Yg1PIr70zbLUsyI86ayDqENKiwbvIyZu4WNY9HH+pbhuSliJiGtOEO1a7kXBQX uBwpcRmyriHDeTT4pjdee0DTY5dsqA31WjDDuYz1t5KBQddvHb9pPynj3xIPIwlGZPUG C0nIyAyWaIVUdQ7pYKgyhVyvUYKyurz2hDj7NGZ7ce6JlUzcesA8/g/lucq/vQYwHv4i hh5VBhkAJL7Pl3XlPqXVClzkN8U+1eQCNJXnEPRJ/gFktVP95uM3yFMr41CRuQqf7eX3 xaVpyd2kuO0szLEKrlGFXsh5lm1I8iVWOdubXA8QfviSDFTgsO1jeFTgPyvMOSeh3lC4 5S2g== Received: by 10.50.46.232 with SMTP id y8mr141541igm.57.1340949324954; Thu, 28 Jun 2012 22:55:24 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.24.148 with SMTP id v20csp75199ibb; Thu, 28 Jun 2012 22:55:24 -0700 (PDT) Received: by 10.216.195.98 with SMTP id o76mr89530wen.202.1340949323586; Thu, 28 Jun 2012 22:55:23 -0700 (PDT) Received: from warmcat.com (warmcat.com. [87.106.134.80]) by mx.google.com with ESMTP id cs8si2949507wib.23.2012.06.28.22.55.22; Thu, 28 Jun 2012 22:55:23 -0700 (PDT) Received-SPF: neutral (google.com: 87.106.134.80 is neither permitted nor denied by best guess record for domain of andy.green@linaro.org) client-ip=87.106.134.80; Authentication-Results: mx.google.com; spf=neutral (google.com: 87.106.134.80 is neither permitted nor denied by best guess record for domain of andy.green@linaro.org) smtp.mail=andy.green@linaro.org Received: from build.warmcat.com (114-36-248-239.dynamic.hinet.net [114.36.248.239]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by warmcat.com (Postfix) with ESMTP id AFEEF403538; Fri, 29 Jun 2012 06:51:25 +0100 (BST) Received: from build.warmcat.com (buildlocal.warmcat.com [127.0.0.1]) by build.warmcat.com (Postfix) with ESMTP id 23899182CA2; Fri, 29 Jun 2012 13:55:19 +0800 (CST) Subject: [PATCH 2/3] OMAP2+ devices add mac address allocation register api To: linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org From: Andy Green Cc: nicolas.pitre@linaro.org, s-jan@ti.com, arnd@arndb.de, patches@linaro.org, tony@atomide.com, rostedt@goodmis.org Date: Fri, 29 Jun 2012 13:55:19 +0800 Message-ID: <20120629055516.11091.82899.stgit@build.warmcat.com> In-Reply-To: <20120629054404.11091.31289.stgit@build.warmcat.com> References: <20120629054404.11091.31289.stgit@build.warmcat.com> User-Agent: StGit/0.16-2-g0d85 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQmF7uOnMtv13yo0AjGEI4AbHtpMqMFK6Inudq3iUPJjP/xGFKofNkb/fYO9KTWZSH6GqIvM From: Andy Green 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 --- 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 #include #include +#include +#include #include #include #include #include #include +#include #include "iomap.h" #include @@ -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)