1/*	$NetBSD: if_sn.c,v 1.45.10.1 2007/06/26 18:12:52 garbled Exp $	*/
2
3/*
4 * National Semiconductor  DP8393X SONIC Driver
5 * Copyright (c) 1991   Algorithmics Ltd (http://www.algor.co.uk)
6 * You may use, copy, and modify this program so long as you retain the
7 * copyright line.
8 *
9 * This driver has been substantially modified since Algorithmics donated
10 * it.
11 *
12 *   Denton Gentry <denny1@home.com>
13 * and also
14 *   Yanagisawa Takeshi <yanagisw@aa.ap.titech.ac.jp>
15 * did the work to get this running on the Macintosh.
16 */
17
18#include <sys/cdefs.h>
19__KERNEL_RCSID(0, "$NetBSD: if_sn.c,v 1.45.10.1 2007/06/26 18:12:52 garbled Exp $");
20
21#include <sys/param.h>
22#include <sys/systm.h>
23
24#include <net/if.h>
25#include <net/if_ether.h>
26
27#include <machine/bus.h>
28
29#include <mac68k/dev/if_snvar.h>
30
31static const uint8_t bbr4[] = {0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};
32#define bbr(v)	((bbr4[(v) & 0xf] << 4) | bbr4[((v) >> 4) & 0xf])
33
34void
35sn_get_enaddr(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
36    uint8_t *dst)
37{
38	int i, do_bbr;
39	uint8_t b;
40
41	/*
42	 * For reasons known only to Apple, MAC addresses in the ethernet
43	 * PROM are stored in Token Ring (IEEE 802.5) format, that is
44	 * with all of the bits in each byte reversed (canonical bit format).
45	 * When the address is read out it must be reversed to ethernet format
46	 * before use.
47	 *
48	 * Apple has been assigned OUI's 08:00:07 and 00:a0:40. All onboard
49	 * ethernet addresses on 68K machines should be in one of these
50	 * two ranges.
51	 *
52	 * Here is where it gets complicated.
53	 *
54	 * The PMac 7200, 7500, 8500, and 9500 accidentally had the PROM
55	 * written in standard ethernet format. The MacOS accounted for this
56	 * in these systems, and did not reverse the bytes. Some other
57	 * networking utilities were not so forgiving, and got confused.
58	 * "Some" of Apple's Nubus ethernet cards also had their bits
59	 * burned in ethernet format.
60	 *
61	 * Apple petitioned the IEEE and was granted the 00:05:02 (bit reversal
62	 * of 00:a0:40) as well. As of OpenTransport 1.1.1, Apple removed
63	 * their workaround and now reverses the bits regardless of
64	 * what kind of machine it is. So PMac systems and the affected
65	 * Nubus cards now use 00:05:02, instead of the 00:a0:40 for which they
66	 * were intended.
67	 *
68	 * See Apple Techinfo article TECHINFO-0020552, "OpenTransport 1.1.1
69	 * and MacOS System 7.5.3 FAQ (10/96)" for more details.
70	 */
71	do_bbr = 0;
72	b = bus_space_read_1(t, h, o);
73	if (b == 0x10)
74		do_bbr = 1;
75	dst[0] = (do_bbr) ? bbr(b) : b;
76
77	for (i = 1 ; i < ETHER_ADDR_LEN ; i++) {
78		b = bus_space_read_1(t, h, o + i);
79		dst[i] = (do_bbr) ? bbr(b) : b;
80	}
81}
82