From patchwork Tue Jul 3 04:22:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: warmcat X-Patchwork-Id: 9775 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 C438223E42 for ; Tue, 3 Jul 2012 04:22:32 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id 8E914A1805A for ; Tue, 3 Jul 2012 04:22:32 +0000 (UTC) Received: by ghbz12 with SMTP id z12so5296143ghb.11 for ; Mon, 02 Jul 2012 21:22:32 -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=ud+A7Y0IP2WVUKV9dblCMoPbRXHEAdoz9TRX/NVqFBs=; b=gAAS+9a010m+FFeDYezlBshTRfHVlRxik8DK5eN0Ve9uzMLfJILu8crGItmHWkMRaH u4RIbemG8yBkoWEY/IQI9hIYvow207zgZH/wPiuads5XEvKLYMwb/Q/1S3M20xgCZgUx bBgnahCYvsLaMLppESY3QQs/A4sLri/oWsKZ63K0H1LnH8tHiyAKc/VJPQ2ddGa4jwPY +OQFV6w3bYvr1Kw1cAhh745BD2UQT1iVJqRKpqYcdFqgtbPQzbCaNWNV9XlANupbBJPx UEPr63tZMBAEEda/j3vGxbqWwJiCNHU9XOi5AUIwCYwQQsGRcxT4i87YaH1gVrBfZbtG mbHQ== Received: by 10.50.163.99 with SMTP id yh3mr7063996igb.53.1341289351683; Mon, 02 Jul 2012 21:22:31 -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 v20csp34893ibb; Mon, 2 Jul 2012 21:22:30 -0700 (PDT) Received: by 10.216.216.226 with SMTP id g76mr3107765wep.221.1341289350505; Mon, 02 Jul 2012 21:22:30 -0700 (PDT) Received: from warmcat.com (warmcat.com. [87.106.134.80]) by mx.google.com with ESMTP id q10si16621168wiy.19.2012.07.02.21.22.30; Mon, 02 Jul 2012 21:22:30 -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 Subject: [PATCH 3 1/4] OMAP: add cpu id register to MAC address helper To: linux-omap@vger.kernel.org From: Andy Green Cc: s-jan@ti.com, arnd@arndb.de, patches@linaro.org, tony@atomide.com, rostedt@goodmis.org, linux-arm-kernel@lists.infradead.org Date: Tue, 03 Jul 2012 12:22:26 +0800 Message-ID: <20120703042224.32697.5128.stgit@build.warmcat.com> In-Reply-To: <20120703041937.32697.46015.stgit@build.warmcat.com> References: <20120703041937.32697.46015.stgit@build.warmcat.com> User-Agent: StGit/0.16-2-g0d85 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQkmQnrtCyDJHpmuoNP5f1gc2qB7bJfjTUAePuRRjSBt0mJ8rcWZZ5EbK2HtXxAthYtLoLVG From: Andy Green Introduce a generic helper function that can generate a valid MAC address using data from the OMAP unique CPU ID register. For comparison purposes this produces a MAC address of 2e:20:3c:ea:46:01 for the ethernet device on my PandaBoard ES. The MAC address space has space set aside for these kind of "locally administered" MAC addresses, analogous to IPv4 10.x.x.x range, and this patch marks the generated MAC addresses as such. The patch leaves two bits allowing elaborating 4 different MACs from the generated data. Signed-off-by: Andy Green Acked-by: Arnd Bergmann Signed-off-by: Nicolas Pitre Tested-by: Steven Rostedt --- arch/arm/mach-omap2/id.c | 39 +++++++++++++++++++++++++++++++++ arch/arm/mach-omap2/include/mach/id.h | 1 + 2 files changed, 40 insertions(+) diff --git a/arch/arm/mach-omap2/id.c b/arch/arm/mach-omap2/id.c index 00486a8..faff686 100644 --- a/arch/arm/mach-omap2/id.c +++ b/arch/arm/mach-omap2/id.c @@ -530,3 +530,42 @@ void __init omap2_set_globals_tap(struct omap_globals *omap2_globals) else tap_prod_id = 0x0208; } + +/* + * this uses the unique per-cpu info from the cpu fuses set at factory to + * generate a 6-byte MAC address. Two bits in the generated code are used + * to elaborate the generated address into four, so it can be used on multiple + * network interfaces. + */ + +void omap_die_id_to_ethernet_mac(u8 *mac, int subtype) +{ + struct omap_die_id odi; + u32 tap = read_tap_reg(OMAP_TAP_IDCODE); + + omap_get_die_id(&odi); + + mac[0] = odi.id_2; + mac[1] = odi.id_2 >> 8; + mac[2] = odi.id_1; + mac[3] = odi.id_1 >> 8; + mac[4] = odi.id_1 >> 16; + mac[5] = odi.id_1 >> 24; + + /* XOR other chip-specific data with ID */ + + tap ^= odi.id_3; + + mac[0] ^= tap; + mac[1] ^= tap >> 8; + mac[2] ^= tap >> 16; + mac[3] ^= tap >> 24; + + /* allow four MACs from this same basic data */ + + mac[1] = (mac[1] & ~0xc0) | ((subtype & 3) << 6); + + /* mark it as not multicast, and outside official 80211 MAC namespace */ + + mac[0] = (mac[0] & ~1) | 2; +} diff --git a/arch/arm/mach-omap2/include/mach/id.h b/arch/arm/mach-omap2/include/mach/id.h index 02ed3aa..d6c8d63 100644 --- a/arch/arm/mach-omap2/include/mach/id.h +++ b/arch/arm/mach-omap2/include/mach/id.h @@ -18,5 +18,6 @@ struct omap_die_id { }; void omap_get_die_id(struct omap_die_id *odi); +void omap_die_id_to_ethernet_mac(u8 *mac, int subtype); #endif