From patchwork Fri Jun 29 05:55:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: warmcat X-Patchwork-Id: 9693 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 6C11323E01 for ; Fri, 29 Jun 2012 05:55:18 +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 1F2A7A180B7 for ; Fri, 29 Jun 2012 05:55:18 +0000 (UTC) Received: by ghbz12 with SMTP id z12so2701743ghb.11 for ; Thu, 28 Jun 2012 22:55:17 -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=Ou9a1l7QK6Wm+m94in40pNGrtmgFneIYnw6Nl1OiMF8=; b=lK0qnyAHcO7lH1sNIc7MrVYTaAX25ePHtnTrEsBgpBuEspSweGCwLilNE5XCurG+7U VeLuOsKXZ7gDIUTcqf+mwHJPYVRdQOGm51N5x70TrxExpAxq+Ogopi//vM0s6NnP0DnX Y6YglPCsKx0U3/S/JR3lwNP/XgEi8UMHzsWgwIGrvj69sM+7GuSsWHZaHLK8owCjFSG+ AoEwqisWfxS3zjSvv6cd4QD4Srd1UejqtCPuV3NamdayyjQ8Xwr2/gmoScgrHNkWiJh6 fkHZ5sTk+eft52Tx2olE4EnwiO1fbJNlD3o5pScdMhf7A+nYEzCbGflo5Yviq6hmKWLg acJA== Received: by 10.50.160.198 with SMTP id xm6mr577165igb.0.1340949317442; Thu, 28 Jun 2012 22:55:17 -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 v20csp75197ibb; Thu, 28 Jun 2012 22:55:16 -0700 (PDT) Received: by 10.180.78.99 with SMTP id a3mr1845634wix.15.1340949315739; Thu, 28 Jun 2012 22:55:15 -0700 (PDT) Received: from warmcat.com (warmcat.com. [87.106.134.80]) by mx.google.com with ESMTP id m17si1572746wee.51.2012.06.28.22.55.14; Thu, 28 Jun 2012 22:55:15 -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 2EF4B403535; Fri, 29 Jun 2012 06:51:18 +0100 (BST) Received: from build.warmcat.com (buildlocal.warmcat.com [127.0.0.1]) by build.warmcat.com (Postfix) with ESMTP id A71F5182CA2; Fri, 29 Jun 2012 13:55:11 +0800 (CST) Subject: [PATCH 1/3] OMAP2+: add cpu id register to MAC address helper 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:11 +0800 Message-ID: <20120629055509.11091.2780.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: ALoCoQlBeyOqUX18WExVHJR/SN9pWEYYiqSmxPUOjz0LnobZPoEeQsZAzlQD1sBCbq7BSZXCEFZl 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:40:70:f0:12:06 for the ethernet device on my Panda. 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..2a44c42 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 omap2_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..373313a 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 omap2_die_id_to_ethernet_mac(u8 *mac, int subtype); #endif