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