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: warmcat X-Patchwork-Id: 9822 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 1FF9823F28 for ; Thu, 5 Jul 2012 02:44:48 +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 D970DA185F0 for ; Thu, 5 Jul 2012 02:44:47 +0000 (UTC) Received: by obbuo19 with SMTP id uo19so13443904obb.11 for ; Wed, 04 Jul 2012 19:44:47 -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=gkD0KMFJQoTdHZuEnNuFtnaoCFtJrwrMvU9YovAEv7c=; b=WBVWZTJWNhXH2SABMoBcZm6aors0hRDjzi7iCQOYfkB/m65zPHx2dfcRKqNI7heFKV g/y5fbvtixXsMCdSP0IpkpuH8cp/tYEzC0eU0tZEV1NjAXXUY9erIFNSDMCFUPJJk9zf Ci+nhOx53RBAboe0iS4EQO9tSIdHLnS8FNJTRPBxj+H9TUiKL/VOhLRI6Mid1xFeO+rm fPWr2Qoqnxo9G7J+Tys2L8FDz7flCihNt6teR+uleaRW5AAKd5eqcglMLhTk/pW4EOvy UYP6vKrJlr8bsp512JD/KjYMBtvpHezGgFrSQDeoOkPdjUAOAlarIrb5kc8QWRxV7r8X EVmg== Received: by 10.50.195.234 with SMTP id ih10mr13086419igc.0.1341456286882; Wed, 04 Jul 2012 19:44:46 -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 v20csp60172ibb; Wed, 4 Jul 2012 19:44:46 -0700 (PDT) Received: by 10.216.213.37 with SMTP id z37mr7912752weo.132.1341456285618; Wed, 04 Jul 2012 19:44:45 -0700 (PDT) Received: from warmcat.com (warmcat.com. [87.106.134.80]) by mx.google.com with ESMTP id u3si40852278wiy.42.2012.07.04.19.44.45; Wed, 04 Jul 2012 19:44:45 -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 4 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, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, rostedt@goodmis.org, linux-arm-kernel@lists.infradead.org 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-Gm-Message-State: ALoCoQlWeF9wsMVjA/b90w8+PQL2gypfykT8CaWD5GaUfHT13QYsUCehoWpeXqKWe5FFoYublhW/ 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