From: Andy Green <andy.green@linaro.org> To: linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: nicolas.pitre@linaro.org, s-jan@ti.com, arnd@arndb.de, patches@linaro.org, tony@atomide.com, rostedt@goodmis.org Subject: [PATCH 1/3] OMAP2+: add cpu id register to MAC address helper Date: Fri, 29 Jun 2012 13:55:11 +0800 [thread overview] Message-ID: <20120629055509.11091.2780.stgit@build.warmcat.com> (raw) In-Reply-To: <20120629054404.11091.31289.stgit@build.warmcat.com> From: Andy Green <andy@warmcat.com> 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 <andy.green@linaro.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Nicolas Pitre <nicolas.pitre@linaro.org> Tested-by: Steven Rostedt <rostedt@goodmis.org> --- 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
WARNING: multiple messages have this Message-ID (diff)
From: andy.green@linaro.org (Andy Green) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/3] OMAP2+: add cpu id register to MAC address helper Date: Fri, 29 Jun 2012 13:55:11 +0800 [thread overview] Message-ID: <20120629055509.11091.2780.stgit@build.warmcat.com> (raw) In-Reply-To: <20120629054404.11091.31289.stgit@build.warmcat.com> From: Andy Green <andy@warmcat.com> 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 <andy.green@linaro.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Nicolas Pitre <nicolas.pitre@linaro.org> Tested-by: Steven Rostedt <rostedt@goodmis.org> --- 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
next prev parent reply other threads:[~2012-06-29 5:55 UTC|newest] Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-06-29 5:55 [PATCH 0/3] Add ability to set defaultless network device MAC addresses to deterministic computed locally administered values Andy Green 2012-06-29 5:55 ` Andy Green 2012-06-29 5:55 ` Andy Green [this message] 2012-06-29 5:55 ` [PATCH 1/3] OMAP2+: add cpu id register to MAC address helper Andy Green 2012-06-29 9:05 ` Tony Lindgren 2012-06-29 9:05 ` Tony Lindgren 2012-06-29 9:13 ` Andy Green 2012-06-29 9:13 ` Andy Green 2012-06-29 5:55 ` [PATCH 2/3] OMAP2+ devices add mac address allocation register api Andy Green 2012-06-29 5:55 ` Andy Green 2012-06-29 8:51 ` Arnd Bergmann 2012-06-29 8:51 ` Arnd Bergmann 2012-06-29 9:03 ` Andy Green 2012-06-29 9:03 ` Andy Green 2012-06-29 9:40 ` Tony Lindgren 2012-06-29 9:40 ` Tony Lindgren 2012-06-29 10:07 ` Andy Green 2012-06-29 10:07 ` Andy Green 2012-06-29 12:03 ` Tony Lindgren 2012-06-29 12:03 ` Tony Lindgren 2012-06-29 13:45 ` Arnd Bergmann 2012-06-29 13:45 ` Arnd Bergmann 2012-06-29 13:55 ` Tony Lindgren 2012-06-29 13:55 ` Tony Lindgren 2012-06-29 13:59 ` Andy Green 2012-06-29 13:59 ` Andy Green 2012-06-29 14:33 ` Arnd Bergmann 2012-06-29 14:33 ` Arnd Bergmann 2012-06-29 14:52 ` Tony Lindgren 2012-06-29 14:52 ` Tony Lindgren 2012-06-29 15:05 ` Arnd Bergmann 2012-06-29 15:05 ` Arnd Bergmann 2012-07-01 8:58 ` Tony Lindgren 2012-07-01 8:58 ` Tony Lindgren 2012-07-02 7:15 ` Arnd Bergmann 2012-07-02 7:15 ` Arnd Bergmann 2012-07-02 10:51 ` Tony Lindgren 2012-07-02 10:51 ` Tony Lindgren 2012-06-29 14:03 ` Andy Green 2012-06-29 14:03 ` Andy Green 2012-06-29 14:38 ` Arnd Bergmann 2012-06-29 14:38 ` Arnd Bergmann 2012-06-29 5:55 ` [PATCH 3/3] OMAP4 PANDA register ethernet and wlan for automatic mac allocation Andy Green 2012-06-29 5:55 ` Andy Green 2012-06-29 11:55 ` Tony Lindgren 2012-06-29 11:55 ` Tony Lindgren 2012-06-29 8:50 ` [PATCH 0/3] Add ability to set defaultless network device MAC addresses to deterministic computed locally administered values Arnd Bergmann 2012-06-29 8:50 ` Arnd Bergmann
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20120629055509.11091.2780.stgit@build.warmcat.com \ --to=andy.green@linaro.org \ --cc=arnd@arndb.de \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-omap@vger.kernel.org \ --cc=nicolas.pitre@linaro.org \ --cc=patches@linaro.org \ --cc=rostedt@goodmis.org \ --cc=s-jan@ti.com \ --cc=tony@atomide.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.