1*d974db0aSgarbled /* $NetBSD: if_sn.c,v 1.47 2007/10/17 19:55:13 garbled Exp $ */
24b6b2bb9Sbriggs
34b6b2bb9Sbriggs /*
436b75f27Sscottr * National Semiconductor DP8393X SONIC Driver
54b6b2bb9Sbriggs * Copyright (c) 1991 Algorithmics Ltd (http://www.algor.co.uk)
64b6b2bb9Sbriggs * You may use, copy, and modify this program so long as you retain the
74b6b2bb9Sbriggs * copyright line.
84b6b2bb9Sbriggs *
94b6b2bb9Sbriggs * This driver has been substantially modified since Algorithmics donated
104b6b2bb9Sbriggs * it.
11c20d7dc9Sbriggs *
12559613a9Sbriggs * Denton Gentry <denny1@home.com>
13c20d7dc9Sbriggs * and also
14b315c448Sbriggs * Yanagisawa Takeshi <yanagisw@aa.ap.titech.ac.jp>
15c20d7dc9Sbriggs * did the work to get this running on the Macintosh.
164b6b2bb9Sbriggs */
174b6b2bb9Sbriggs
184b2744bfSlukem #include <sys/cdefs.h>
19*d974db0aSgarbled __KERNEL_RCSID(0, "$NetBSD: if_sn.c,v 1.47 2007/10/17 19:55:13 garbled Exp $");
203751946bSjonathan
214b6b2bb9Sbriggs #include <sys/param.h>
224b6b2bb9Sbriggs #include <sys/systm.h>
2371cdc2ebSthorpej
244b6b2bb9Sbriggs #include <net/if.h>
25530a88d1Sis #include <net/if_ether.h>
264b6b2bb9Sbriggs
274b6b2bb9Sbriggs #include <machine/bus.h>
28aa9fb966Stsutsui
294b6b2bb9Sbriggs #include <mac68k/dev/if_snvar.h>
304b6b2bb9Sbriggs
31aa9fb966Stsutsui static const uint8_t bbr4[] = {0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};
324a3016b6Sbriggs #define bbr(v) ((bbr4[(v) & 0xf] << 4) | bbr4[((v) >> 4) & 0xf])
334a3016b6Sbriggs
344a3016b6Sbriggs void
sn_get_enaddr(bus_space_tag_t t,bus_space_handle_t h,bus_size_t o,uint8_t * dst)357acd68b1Schs sn_get_enaddr(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
36aa9fb966Stsutsui uint8_t *dst)
374a3016b6Sbriggs {
384a3016b6Sbriggs int i, do_bbr;
39aa9fb966Stsutsui uint8_t b;
404a3016b6Sbriggs
414a3016b6Sbriggs /*
424a3016b6Sbriggs * For reasons known only to Apple, MAC addresses in the ethernet
434a3016b6Sbriggs * PROM are stored in Token Ring (IEEE 802.5) format, that is
444a3016b6Sbriggs * with all of the bits in each byte reversed (canonical bit format).
454a3016b6Sbriggs * When the address is read out it must be reversed to ethernet format
464a3016b6Sbriggs * before use.
474a3016b6Sbriggs *
484a3016b6Sbriggs * Apple has been assigned OUI's 08:00:07 and 00:a0:40. All onboard
494a3016b6Sbriggs * ethernet addresses on 68K machines should be in one of these
504a3016b6Sbriggs * two ranges.
514a3016b6Sbriggs *
524a3016b6Sbriggs * Here is where it gets complicated.
534a3016b6Sbriggs *
544a3016b6Sbriggs * The PMac 7200, 7500, 8500, and 9500 accidentally had the PROM
554a3016b6Sbriggs * written in standard ethernet format. The MacOS accounted for this
564a3016b6Sbriggs * in these systems, and did not reverse the bytes. Some other
574a3016b6Sbriggs * networking utilities were not so forgiving, and got confused.
584a3016b6Sbriggs * "Some" of Apple's Nubus ethernet cards also had their bits
594a3016b6Sbriggs * burned in ethernet format.
604a3016b6Sbriggs *
614a3016b6Sbriggs * Apple petitioned the IEEE and was granted the 00:05:02 (bit reversal
624a3016b6Sbriggs * of 00:a0:40) as well. As of OpenTransport 1.1.1, Apple removed
634a3016b6Sbriggs * their workaround and now reverses the bits regardless of
644a3016b6Sbriggs * what kind of machine it is. So PMac systems and the affected
654a3016b6Sbriggs * Nubus cards now use 00:05:02, instead of the 00:a0:40 for which they
664a3016b6Sbriggs * were intended.
674a3016b6Sbriggs *
684a3016b6Sbriggs * See Apple Techinfo article TECHINFO-0020552, "OpenTransport 1.1.1
694a3016b6Sbriggs * and MacOS System 7.5.3 FAQ (10/96)" for more details.
704a3016b6Sbriggs */
714a3016b6Sbriggs do_bbr = 0;
724a3016b6Sbriggs b = bus_space_read_1(t, h, o);
734a3016b6Sbriggs if (b == 0x10)
744a3016b6Sbriggs do_bbr = 1;
754a3016b6Sbriggs dst[0] = (do_bbr) ? bbr(b) : b;
764a3016b6Sbriggs
774a3016b6Sbriggs for (i = 1 ; i < ETHER_ADDR_LEN ; i++) {
784a3016b6Sbriggs b = bus_space_read_1(t, h, o + i);
794a3016b6Sbriggs dst[i] = (do_bbr) ? bbr(b) : b;
804a3016b6Sbriggs }
814a3016b6Sbriggs }
82