if_sn_obio.c revision 1.2 1 /* $NetBSD: if_sn_obio.c,v 1.2 1997/03/16 13:41:16 is Exp $ */
2
3 /*
4 * Copyright (C) 1997 Allen Briggs
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Allen Briggs
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include <sys/param.h>
34 #include <sys/device.h>
35 #include <sys/errno.h>
36 #include <sys/ioctl.h>
37 #include <sys/socket.h>
38 #include <sys/syslog.h>
39 #include <sys/systm.h>
40
41 #include <net/if.h>
42 #include <net/if_ether.h>
43
44 #if 0 /* XXX this shouldn't be necessary... else reinsert */
45 #ifdef INET
46 #include <netinet/in.h>
47 #include <netinet/if_ether.h>
48 #endif
49 #endif
50
51 #include <machine/bus.h>
52 #include <machine/cpu.h>
53 #include <machine/viareg.h>
54
55 #include "obiovar.h"
56 #include "if_snreg.h"
57 #include "if_snvar.h"
58
59 #define SONIC_REG_BASE 0x50F0A000
60 #define SONIC_PROM_BASE 0x50F08000
61
62 static int sn_obio_match __P((struct device *, struct cfdata *, void *));
63 static void sn_obio_attach __P((struct device *, struct device *, void *));
64 static void sn_obio_getaddr __P((struct sn_softc *));
65
66 struct cfattach sn_obio_ca = {
67 sizeof(struct sn_softc), sn_obio_match, sn_obio_attach
68 };
69
70 static int
71 sn_obio_match(parent, cf, aux)
72 struct device *parent;
73 struct cfdata *cf;
74 void *aux;
75 {
76 if (mac68k_machine.sonic)
77 return 1;
78
79 return 0;
80 }
81
82 /*
83 * Install interface into kernel networking data structures
84 */
85 static void
86 sn_obio_attach(parent, self, aux)
87 struct device *parent, *self;
88 void *aux;
89 {
90 struct obio_attach_args *oa = (struct obio_attach_args *) aux;
91 struct sn_softc *sc = (void *)self;
92 u_int8_t myaddr[ETHER_ADDR_LEN];
93
94 sc->s_dcr = DCR_LBR | DCR_SYNC | DCR_WAIT0 |
95 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
96
97 switch (current_mac_model->class) {
98 case MACH_CLASSQ:
99 case MACH_CLASSQ2:
100 sc->s_dcr |= DCR_DW32;
101 sc->bitmode = 1;
102 break;
103
104 case MACH_CLASSPB:
105 sc->s_dcr |= DCR_DW16;
106 sc->bitmode = 0;
107 return;
108
109 default:
110 printf("unsupported machine type\n");
111 return;
112 }
113
114 sc->sc_regt = oa->oa_tag;
115 if (bus_space_map(sc->sc_regt, SONIC_REG_BASE, SN_REGSIZE,
116 0, &sc->sc_regh)) {
117 panic("failed to map space for SONIC regs.\n");
118 }
119
120 sc->slotno = 9;
121
122 sn_obio_getaddr(sc, myaddr);
123
124 snsetup(sc, myaddr);
125 }
126
127 static u_char bbr4[] = {0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};
128 #define bbr(v) ((bbr4[(v)&0xf] << 4) | bbr4[((v)>>4) & 0xf])
129
130 static void
131 sn_obio_getaddr(sc, lladdr)
132 struct sn_softc *sc;
133 u_int8_t *lladdr;
134 {
135 bus_space_handle_t bsh;
136 int i, do_bbr;
137 u_char b;
138
139 if (bus_space_map(sc->sc_regt, SONIC_PROM_BASE, NBPG, 0, &bsh)) {
140 panic("failed to map space to read SONIC address.\n");
141 }
142
143 /*
144 * Apparently Apple goofed here. The ethernet MAC address is
145 * stored in bit-byte-reversed format. It is rumored that this
146 * is only true for some systems.
147 */
148 do_bbr = 0;
149 b = bus_space_read_1(sc->sc_regt, bsh, 0);
150 if (b == 0x10)
151 do_bbr = 1;
152 lladdr[0] = (do_bbr) ? bbr(b) : b;
153
154 for (i = 1 ; i < ETHER_ADDR_LEN ; i++) {
155 b = bus_space_read_1(sc->sc_regt, bsh, i);
156 lladdr[i] = (do_bbr) ? bbr(b) : b;
157 }
158
159 bus_space_unmap(sc->sc_regt, bsh, NBPG);
160 }
161