From patchwork Mon Jul 2 06:40:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: warmcat X-Patchwork-Id: 9723 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 D5CD423E37 for ; Mon, 2 Jul 2012 06:40:55 +0000 (UTC) Received: from mail-yw0-f47.google.com (mail-yw0-f47.google.com [209.85.213.47]) by fiordland.canonical.com (Postfix) with ESMTP id A57E5A181F4 for ; Mon, 2 Jul 2012 06:40:55 +0000 (UTC) Received: by yhjj56 with SMTP id j56so4789756yhj.20 for ; Sun, 01 Jul 2012 23:40:55 -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=rNbu3Ef3cVeiMjTxaPknNNkccGdKgurjW3drTcy4vwA=; b=cOaBf9qkQx2PgZuDb9ha+2uOlI56NJC2+vJTx4PoCvqvkLHr3qArhRJD0hx//Yi3NA pc0E0oJnpOO5hvY55xyzZxE6/k+UA3Dlvb/EbCgbSNjMwtDU3PgLR/TTTqIhVJZrpjvy dI+6y3O5ZSCVm553jDSMN8LoSumgKDdk9kkkAugWiQtBnd9dOBYF4s496nvOTc9oSNP2 itrGGWJsGCoIgjHJkJvlNFceNnjb63geQ06TQoDz/gYzWu2kUYtjqwP48LHCEds4T29Z 54BakwYl+GtkrWbtsED9l8QhavpDrHmxWksz8ATLzntXe5nW9BAfWK8sJa+MArysSAaX mwQA== Received: by 10.50.193.196 with SMTP id hq4mr4435316igc.57.1341211254958; Sun, 01 Jul 2012 23:40:54 -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 v20csp18095ibb; Sun, 1 Jul 2012 23:40:54 -0700 (PDT) Received: by 10.216.71.82 with SMTP id q60mr1286134wed.64.1341211253295; Sun, 01 Jul 2012 23:40:53 -0700 (PDT) Received: from warmcat.com (warmcat.com. [87.106.134.80]) by mx.google.com with ESMTP id w9si6446720wew.130.2012.07.01.23.40.52; Sun, 01 Jul 2012 23:40:53 -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 2 1/4] OMAP2+: 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: Mon, 02 Jul 2012 14:40:49 +0800 Message-ID: <20120702064046.26782.32399.stgit@build.warmcat.com> In-Reply-To: <20120702063545.26782.98908.stgit@build.warmcat.com> References: <20120702063545.26782.98908.stgit@build.warmcat.com> User-Agent: StGit/0.16-2-g0d85 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQkBQQ6yRERAOdFA565FHSQ1pMchX+HN5eQkWg2qU/Xp5di8nmrqnuuEmm5VhzyaOV5ddqlm 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..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