if_sn_nubus.c revision 1.23 1 /* $NetBSD: if_sn_nubus.c,v 1.23 2003/07/15 02:43:24 lukem 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/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: if_sn_nubus.c,v 1.23 2003/07/15 02:43:24 lukem Exp $");
35
36 #include "opt_inet.h"
37
38 #include <sys/param.h>
39 #include <sys/device.h>
40 #include <sys/errno.h>
41 #include <sys/ioctl.h>
42 #include <sys/socket.h>
43 #include <sys/syslog.h>
44 #include <sys/systm.h>
45
46 #include <net/if.h>
47 #include <net/if_ether.h>
48
49 #if 0 /* XXX this shouldn't be necessary; else reinsert */
50 #ifdef INET
51 #include <netinet/in.h>
52 #include <netinet/if_inarp.h>
53 #endif
54 #endif
55
56 #include <machine/bus.h>
57 #include <machine/viareg.h>
58
59 #include <mac68k/nubus/nubus.h>
60 #include <mac68k/dev/if_snreg.h>
61 #include <mac68k/dev/if_snvar.h>
62
63 static int sn_nubus_match __P((struct device *, struct cfdata *, void *));
64 static void sn_nubus_attach __P((struct device *, struct device *, void *));
65 static int sn_nb_card_vendor __P((bus_space_tag_t, bus_space_handle_t,
66 struct nubus_attach_args *));
67
68 CFATTACH_DECL(sn_nubus, sizeof(struct sn_softc),
69 sn_nubus_match, sn_nubus_attach, NULL, NULL);
70
71
72 static int
73 sn_nubus_match(parent, cf, aux)
74 struct device *parent;
75 struct cfdata *cf;
76 void *aux;
77 {
78 struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
79 bus_space_handle_t bsh;
80 int rv;
81
82 if (bus_space_map(na->na_tag,
83 NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh))
84 return (0);
85
86 rv = 0;
87
88 if (na->category == NUBUS_CATEGORY_NETWORK &&
89 na->type == NUBUS_TYPE_ETHERNET) {
90 switch (sn_nb_card_vendor(na->na_tag, bsh, na)) {
91 default:
92 break;
93
94 case SN_VENDOR_APPLE:
95 case SN_VENDOR_APPLE16:
96 case SN_VENDOR_ASANTELC:
97 case SN_VENDOR_DAYNA:
98 rv = 1;
99 break;
100 }
101 }
102
103 bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
104
105 return rv;
106 }
107
108 /*
109 * Install interface into kernel networking data structures
110 */
111 static void
112 sn_nubus_attach(parent, self, aux)
113 struct device *parent, *self;
114 void *aux;
115 {
116 struct sn_softc *sc = (void *)self;
117 struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
118 int i, success, offset;
119 bus_space_tag_t bst;
120 bus_space_handle_t bsh, tmp_bsh;
121 u_int8_t myaddr[ETHER_ADDR_LEN];
122 char *cardtype;
123
124 (void)(&offset); /* Work around lame gcc initialization bug */
125
126 bst = na->na_tag;
127 if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
128 printf(": failed to map memory space.\n");
129 return;
130 }
131
132 sc->sc_regt = bst;
133
134 cardtype = nubus_get_card_name(bst, bsh, na->fmt);
135
136 success = 0;
137
138 sc->slotno = na->slot;
139
140 switch (sn_nb_card_vendor(bst, bsh, na)) {
141 case SN_VENDOR_DAYNA:
142 sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
143 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
144 sc->snr_dcr2 = 0;
145 sc->bitmode = 1; /* 32 bit card */
146
147 if (bus_space_subregion(bst, bsh,
148 0x00180000, SN_REGSIZE, &sc->sc_regh)) {
149 printf(": failed to map register space.\n");
150 break;
151 }
152
153 if (bus_space_subregion(bst, bsh,
154 0x00ffe004, ETHER_ADDR_LEN, &tmp_bsh)) {
155 printf(": failed to map ROM space.\n");
156 break;
157 }
158
159 sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
160
161 offset = 2;
162 success = 1;
163 break;
164
165 case SN_VENDOR_APPLE:
166 sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
167 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
168 sc->snr_dcr2 = 0;
169 sc->bitmode = 1; /* 32 bit card */
170
171 if (bus_space_subregion(bst, bsh,
172 0x0, SN_REGSIZE, &sc->sc_regh)) {
173 printf(": failed to map register space.\n");
174 break;
175 }
176
177 if (bus_space_subregion(bst, bsh,
178 0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
179 printf(": failed to map ROM space.\n");
180 break;
181 }
182
183 sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
184
185 offset = 0;
186 success = 1;
187 break;
188
189 case SN_VENDOR_APPLE16:
190 sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_EXBUS |
191 DCR_DMABLOCK | DCR_PO1 | DCR_RFT16 | DCR_TFT16;
192 sc->snr_dcr2 = 0;
193 sc->bitmode = 0; /* 16 bit card */
194
195 if (bus_space_subregion(bst, bsh,
196 0x0, SN_REGSIZE, &sc->sc_regh)) {
197 printf(": failed to map register space.\n");
198 break;
199 }
200
201 if (bus_space_subregion(bst, bsh,
202 0x40000, ETHER_ADDR_LEN, &tmp_bsh)) {
203 printf(": failed to map ROM space.\n");
204 break;
205 }
206
207 sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
208
209 offset = 0;
210 success = 1;
211 break;
212
213 case SN_VENDOR_ASANTELC: /* Macintosh LC Ethernet Adapter */
214 sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
215 DCR_DMABLOCK | DCR_PO1 | DCR_RFT16 | DCR_TFT16;
216 sc->snr_dcr2 = 0;
217 sc->bitmode = 0; /* 16 bit card */
218
219 if (bus_space_subregion(bst, bsh,
220 0x0, SN_REGSIZE, &sc->sc_regh)) {
221 printf(": failed to map register space.\n");
222 break;
223 }
224
225 if (bus_space_subregion(bst, bsh,
226 0x400000, ETHER_ADDR_LEN, &tmp_bsh)) {
227 printf(": failed to map ROM space.\n");
228 break;
229 }
230
231 sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
232
233 offset = 0;
234 success = 1;
235 break;
236
237 default:
238 /*
239 * You can't actually get this default, the snmatch
240 * will fail for unknown hardware. If you're adding support
241 * for a new card, the following defaults are a
242 * good starting point.
243 */
244 sc->snr_dcr = DCR_SYNC | DCR_WAIT0 | DCR_DW32 |
245 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
246 sc->snr_dcr2 = 0;
247 success = 0;
248 printf(": unknown card: attachment incomplete.\n");
249 }
250
251 if (!success) {
252 bus_space_unmap(bst, bsh, NBMEMSIZE);
253 return;
254 }
255
256 /* Regs are addressed as words, big endian. */
257 for (i = 0; i < SN_NREGS; i++) {
258 sc->sc_reg_map[i] = (bus_size_t)((i * 4) + offset);
259 }
260
261 printf(": %s\n", cardtype);
262
263 /* snsetup returns 1 if something fails */
264 if (snsetup(sc, myaddr)) {
265 bus_space_unmap(bst, bsh, NBMEMSIZE);
266 return;
267 }
268
269 add_nubus_intr(sc->slotno, snintr, (void *)sc);
270
271 return;
272 }
273
274 static int
275 sn_nb_card_vendor(bst, bsh, na)
276 bus_space_tag_t bst;
277 bus_space_handle_t bsh;
278 struct nubus_attach_args *na;
279 {
280 int vendor = SN_VENDOR_UNKNOWN;
281
282 switch (na->drsw) {
283 case NUBUS_DRSW_3COM:
284 if (na->drhw == NUBUS_DRHW_APPLE_SNT)
285 vendor = SN_VENDOR_APPLE;
286 else if (na->drhw == NUBUS_DRHW_APPLE_SN)
287 vendor = SN_VENDOR_APPLE16;
288 break;
289 case NUBUS_DRSW_APPLE:
290 if (na->drhw == NUBUS_DRHW_ASANTE_LC)
291 vendor = SN_VENDOR_ASANTELC;
292 else
293 vendor = SN_VENDOR_APPLE;
294 break;
295 case NUBUS_DRSW_TECHWORKS:
296 vendor = SN_VENDOR_APPLE;
297 break;
298 case NUBUS_DRSW_GATOR:
299 if (na->drhw == NUBUS_DRHW_KINETICS &&
300 strncmp(nubus_get_card_name(bst, bsh, na->fmt),
301 "EtherPort", 9) != 0)
302 vendor = SN_VENDOR_DAYNA;
303 break;
304 case NUBUS_DRSW_DAYNA:
305 vendor = SN_VENDOR_DAYNA;
306 break;
307 }
308
309 return vendor;
310 }
311