From patchwork Thu Jul 5 02:44:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Green X-Patchwork-Id: 1157831 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 920BDDFF0F for ; Thu, 5 Jul 2012 02:51:10 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Smc4G-0007ze-7R; Thu, 05 Jul 2012 02:45:20 +0000 Received: from bombadil.infradead.org ([2001:4830:2446:ff00:4687:fcff:fea6:5117]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Smc45-0007zZ-4I for linux-arm-kernel@merlin.infradead.org; Thu, 05 Jul 2012 02:45:09 +0000 Received: from warmcat.com ([87.106.134.80]) by bombadil.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Smc41-0002Q9-Iq for linux-arm-kernel@lists.infradead.org; Thu, 05 Jul 2012 02:45:07 +0000 Subject: [PATCH 4 1/4] OMAP: add cpu id register to MAC address helper To: linux-omap@vger.kernel.org From: Andy Green Date: Thu, 05 Jul 2012 10:44:41 +0800 Message-ID: <20120705024439.26317.84637.stgit@build.warmcat.com> In-Reply-To: <20120705024259.26317.16000.stgit@build.warmcat.com> References: <20120705024259.26317.16000.stgit@build.warmcat.com> User-Agent: StGit/0.16-2-g0d85 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20120704_224506_014963_DA549AE2 X-CRM114-Status: GOOD ( 12.11 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: s-jan@ti.com, arnd@arndb.de, patches@linaro.org, tony@atomide.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, rostedt@goodmis.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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 37eb95a..3ab5d4d 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