if_ae_nubus.c revision 1.12 1 1.12 briggs /* $NetBSD: if_ae_nubus.c,v 1.12 1997/04/10 03:19:46 briggs Exp $ */
2 1.1 scottr
3 1.1 scottr /*
4 1.1 scottr * Copyright (C) 1997 Scott Reynolds
5 1.1 scottr * All rights reserved.
6 1.1 scottr *
7 1.1 scottr * Redistribution and use in source and binary forms, with or without
8 1.1 scottr * modification, are permitted provided that the following conditions
9 1.1 scottr * are met:
10 1.1 scottr * 1. Redistributions of source code must retain the above copyright
11 1.1 scottr * notice, this list of conditions and the following disclaimer.
12 1.1 scottr * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 scottr * notice, this list of conditions and the following disclaimer in the
14 1.1 scottr * documentation and/or other materials provided with the distribution.
15 1.1 scottr * 3. All advertising materials mentioning features or use of this software
16 1.1 scottr * must display the following acknowledgement:
17 1.1 scottr * This product includes software developed by Scott Reynolds for
18 1.1 scottr * the NetBSD Project.
19 1.1 scottr * 4. The name of the author may not be used to endorse or promote products
20 1.1 scottr * derived from this software without specific prior written permission.
21 1.1 scottr *
22 1.1 scottr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 scottr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 scottr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 scottr * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 scottr * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 scottr * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 scottr * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 scottr * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 scottr * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 scottr * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 scottr */
33 1.11 scottr /*
34 1.11 scottr * Some parts are derived from code adapted for MacBSD by Brad Parker
35 1.11 scottr * <brad (at) fcr.com>.
36 1.11 scottr *
37 1.11 scottr * Currently supports:
38 1.11 scottr * Apple NB Ethernet Card
39 1.11 scottr * Apple NB Ethernet Card II
40 1.11 scottr * Interlan A310 NuBus Ethernet card
41 1.11 scottr * Cayman Systems GatorCard
42 1.11 scottr * Asante MacCon II/E
43 1.11 scottr * Kinetics EtherPort SE/30
44 1.11 scottr */
45 1.1 scottr
46 1.1 scottr #include <sys/param.h>
47 1.1 scottr #include <sys/device.h>
48 1.1 scottr #include <sys/errno.h>
49 1.1 scottr #include <sys/ioctl.h>
50 1.1 scottr #include <sys/socket.h>
51 1.4 scottr #include <sys/syslog.h>
52 1.1 scottr #include <sys/systm.h>
53 1.1 scottr
54 1.1 scottr #include <net/if.h>
55 1.7 is #include <net/if_ether.h>
56 1.1 scottr
57 1.1 scottr #ifdef INET
58 1.1 scottr #include <netinet/in.h>
59 1.7 is #include <netinet/if_inarp.h>
60 1.1 scottr #endif
61 1.1 scottr
62 1.1 scottr #include <machine/bus.h>
63 1.1 scottr #include <machine/viareg.h>
64 1.1 scottr
65 1.1 scottr #include "nubus.h"
66 1.1 scottr #include <dev/ic/dp8390reg.h>
67 1.1 scottr #include "if_aereg.h"
68 1.1 scottr #include "if_aevar.h"
69 1.1 scottr
70 1.1 scottr static int ae_nubus_match __P((struct device *, struct cfdata *, void *));
71 1.1 scottr static void ae_nubus_attach __P((struct device *, struct device *, void *));
72 1.4 scottr static int ae_nb_card_vendor __P((struct nubus_attach_args *));
73 1.4 scottr static int ae_nb_get_enaddr __P((struct nubus_attach_args *, u_int8_t *));
74 1.11 scottr #ifdef DEBUG
75 1.4 scottr static void ae_nb_watchdog __P((struct ifnet *));
76 1.11 scottr #endif
77 1.1 scottr
78 1.1 scottr struct cfattach ae_nubus_ca = {
79 1.1 scottr sizeof(struct ae_softc), ae_nubus_match, ae_nubus_attach
80 1.1 scottr };
81 1.1 scottr
82 1.1 scottr static int
83 1.1 scottr ae_nubus_match(parent, cf, aux)
84 1.1 scottr struct device *parent;
85 1.1 scottr struct cfdata *cf;
86 1.1 scottr void *aux;
87 1.1 scottr {
88 1.1 scottr struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
89 1.1 scottr bus_space_handle_t bsh;
90 1.1 scottr int rv;
91 1.1 scottr
92 1.1 scottr if (bus_space_map(na->na_tag, NUBUS_SLOT2PA(na->slot), NBMEMSIZE,
93 1.1 scottr 0, &bsh))
94 1.1 scottr return (0);
95 1.1 scottr
96 1.1 scottr rv = 0;
97 1.1 scottr
98 1.1 scottr if (na->category == NUBUS_CATEGORY_NETWORK &&
99 1.1 scottr na->type == NUBUS_TYPE_ETHERNET) {
100 1.4 scottr switch (ae_nb_card_vendor(na)) {
101 1.1 scottr case AE_VENDOR_APPLE:
102 1.1 scottr case AE_VENDOR_ASANTE:
103 1.1 scottr case AE_VENDOR_FARALLON:
104 1.1 scottr case AE_VENDOR_INTERLAN:
105 1.2 scottr case AE_VENDOR_KINETICS:
106 1.1 scottr rv = 1;
107 1.1 scottr break;
108 1.1 scottr case AE_VENDOR_DAYNA:
109 1.1 scottr case AE_VENDOR_FOCUS:
110 1.1 scottr rv = UNSUPP;
111 1.1 scottr break;
112 1.1 scottr default:
113 1.1 scottr break;
114 1.1 scottr }
115 1.1 scottr }
116 1.1 scottr
117 1.1 scottr bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
118 1.1 scottr
119 1.1 scottr return rv;
120 1.1 scottr }
121 1.1 scottr
122 1.1 scottr /*
123 1.1 scottr * Install interface into kernel networking data structures
124 1.1 scottr */
125 1.1 scottr static void
126 1.1 scottr ae_nubus_attach(parent, self, aux)
127 1.1 scottr struct device *parent, *self;
128 1.1 scottr void *aux;
129 1.1 scottr {
130 1.1 scottr struct ae_softc *sc = (struct ae_softc *) self;
131 1.1 scottr struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
132 1.11 scottr #ifdef DEBUG
133 1.7 is struct ifnet *ifp = &sc->sc_ec.ec_if;
134 1.11 scottr #endif
135 1.1 scottr bus_space_tag_t bst;
136 1.1 scottr bus_space_handle_t bsh;
137 1.11 scottr int i, success;
138 1.7 is u_int8_t myaddr[ETHER_ADDR_LEN];
139 1.1 scottr
140 1.1 scottr bst = na->na_tag;
141 1.1 scottr if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE,
142 1.1 scottr 0, &bsh)) {
143 1.1 scottr printf(": can't map memory space\n");
144 1.1 scottr return;
145 1.1 scottr }
146 1.1 scottr
147 1.4 scottr sc->sc_regt = sc->sc_buft = bst;
148 1.3 scottr sc->sc_flags = self->dv_cfdata->cf_flags;
149 1.2 scottr sc->use16bit = 1;
150 1.4 scottr sc->vendor = ae_nb_card_vendor(na);
151 1.1 scottr strncpy(sc->type_str, nubus_get_card_name(na->fmt),
152 1.1 scottr INTERFACE_NAME_LEN);
153 1.1 scottr sc->type_str[INTERFACE_NAME_LEN-1] = '\0';
154 1.1 scottr sc->mem_size = 0;
155 1.1 scottr
156 1.1 scottr success = 0;
157 1.1 scottr
158 1.1 scottr switch (sc->vendor) {
159 1.3 scottr case AE_VENDOR_APPLE: /* Apple-compatible cards */
160 1.1 scottr case AE_VENDOR_ASANTE:
161 1.11 scottr /* Map register offsets */
162 1.11 scottr for (i = 0; i < 16; i++) /* reverse order, longword aligned */
163 1.11 scottr sc->sc_reg_map[i] = (15 - i) << 2;
164 1.11 scottr
165 1.1 scottr if (bus_space_subregion(bst, bsh,
166 1.4 scottr AE_REG_OFFSET, AE_REG_SIZE, &sc->sc_regh)) {
167 1.1 scottr printf(": failed to map register space\n");
168 1.1 scottr break;
169 1.1 scottr }
170 1.1 scottr if ((sc->mem_size = ae_size_card_memory(bst, bsh,
171 1.1 scottr AE_DATA_OFFSET)) == 0) {
172 1.1 scottr printf(": failed to determine size of RAM.\n");
173 1.1 scottr break;
174 1.1 scottr }
175 1.1 scottr if (bus_space_subregion(bst, bsh,
176 1.4 scottr AE_DATA_OFFSET, sc->mem_size, &sc->sc_bufh)) {
177 1.1 scottr printf(": failed to map register space\n");
178 1.1 scottr break;
179 1.1 scottr }
180 1.3 scottr #ifdef AE_OLD_GET_ENADDR
181 1.1 scottr /* Get station address from on-board ROM */
182 1.1 scottr for (i = 0; i < ETHER_ADDR_LEN; ++i)
183 1.7 is myaddr[i] =
184 1.1 scottr bus_space_read_1(bst, bsh, (AE_ROM_OFFSET + i * 2));
185 1.3 scottr #else
186 1.7 is if (ae_nb_get_enaddr(na, myaddr)) {
187 1.3 scottr printf(": can't find MAC address\n");
188 1.3 scottr break;
189 1.3 scottr }
190 1.3 scottr #endif
191 1.1 scottr
192 1.1 scottr success = 1;
193 1.1 scottr break;
194 1.1 scottr
195 1.1 scottr case AE_VENDOR_DAYNA:
196 1.11 scottr /* Map register offsets */
197 1.11 scottr for (i = 0; i < 16; i++) /* normal order, longword aligned */
198 1.11 scottr sc->sc_reg_map[i] = i << 2;
199 1.11 scottr
200 1.1 scottr if (bus_space_subregion(bst, bsh,
201 1.4 scottr DP_REG_OFFSET, AE_REG_SIZE, &sc->sc_regh)) {
202 1.1 scottr printf(": failed to map register space\n");
203 1.1 scottr break;
204 1.1 scottr }
205 1.1 scottr sc->mem_size = 8192;
206 1.1 scottr if (bus_space_subregion(bst, bsh,
207 1.4 scottr DP_DATA_OFFSET, sc->mem_size, &sc->sc_bufh)) {
208 1.1 scottr printf(": failed to map register space\n");
209 1.1 scottr break;
210 1.1 scottr }
211 1.3 scottr #ifdef AE_OLD_GET_ENADDR
212 1.1 scottr /* Get station address from on-board ROM */
213 1.1 scottr for (i = 0; i < ETHER_ADDR_LEN; ++i)
214 1.7 is myaddr[i] =
215 1.1 scottr bus_space_read_1(bst, bsh, (DP_ROM_OFFSET + i * 2));
216 1.3 scottr #else
217 1.7 is if (ae_nb_get_enaddr(na, myaddr)) {
218 1.3 scottr printf(": can't find MAC address\n");
219 1.3 scottr break;
220 1.3 scottr }
221 1.3 scottr #endif
222 1.1 scottr
223 1.1 scottr printf(": unsupported Dayna hardware\n");
224 1.1 scottr break;
225 1.1 scottr
226 1.1 scottr case AE_VENDOR_FARALLON:
227 1.11 scottr /* Map register offsets */
228 1.11 scottr for (i = 0; i < 16; i++) /* reverse order, longword aligned */
229 1.11 scottr sc->sc_reg_map[i] = (15 - i) << 2;
230 1.11 scottr
231 1.1 scottr if (bus_space_subregion(bst, bsh,
232 1.4 scottr AE_REG_OFFSET, AE_REG_SIZE, &sc->sc_regh)) {
233 1.1 scottr printf(": failed to map register space\n");
234 1.1 scottr break;
235 1.1 scottr }
236 1.1 scottr if ((sc->mem_size = ae_size_card_memory(bst, bsh,
237 1.1 scottr AE_DATA_OFFSET)) == 0) {
238 1.1 scottr printf(": failed to determine size of RAM.\n");
239 1.1 scottr break;
240 1.1 scottr }
241 1.1 scottr if (bus_space_subregion(bst, bsh,
242 1.4 scottr AE_DATA_OFFSET, sc->mem_size, &sc->sc_bufh)) {
243 1.1 scottr printf(": failed to map register space\n");
244 1.1 scottr break;
245 1.1 scottr }
246 1.3 scottr #ifdef AE_OLD_GET_ENADDR
247 1.1 scottr /* Get station address from on-board ROM */
248 1.1 scottr for (i = 0; i < ETHER_ADDR_LEN; ++i)
249 1.7 is myaddr[i] =
250 1.1 scottr bus_space_read_1(bst, bsh, (FE_ROM_OFFSET + i));
251 1.6 scottr #else
252 1.7 is if (ae_nb_get_enaddr(na, myaddr)) {
253 1.6 scottr printf(": can't find MAC address\n");
254 1.6 scottr break;
255 1.6 scottr }
256 1.3 scottr #endif
257 1.1 scottr
258 1.1 scottr success = 1;
259 1.1 scottr break;
260 1.1 scottr
261 1.1 scottr case AE_VENDOR_FOCUS:
262 1.1 scottr printf(": unsupported Focus hardware\n");
263 1.1 scottr break;
264 1.1 scottr
265 1.3 scottr case AE_VENDOR_INTERLAN:
266 1.11 scottr /* Map register offsets */
267 1.11 scottr for (i = 0; i < 16; i++) /* normal order, longword aligned */
268 1.11 scottr sc->sc_reg_map[i] = i << 2;
269 1.11 scottr
270 1.2 scottr if (bus_space_subregion(bst, bsh,
271 1.4 scottr GC_REG_OFFSET, AE_REG_SIZE, &sc->sc_regh)) {
272 1.2 scottr printf(": failed to map register space\n");
273 1.2 scottr break;
274 1.2 scottr }
275 1.2 scottr if ((sc->mem_size = ae_size_card_memory(bst, bsh,
276 1.3 scottr GC_DATA_OFFSET)) == 0) {
277 1.2 scottr printf(": failed to determine size of RAM.\n");
278 1.2 scottr break;
279 1.2 scottr }
280 1.2 scottr if (bus_space_subregion(bst, bsh,
281 1.4 scottr GC_DATA_OFFSET, sc->mem_size, &sc->sc_bufh)) {
282 1.2 scottr printf(": failed to map register space\n");
283 1.2 scottr break;
284 1.2 scottr }
285 1.2 scottr
286 1.3 scottr /* reset the NIC chip */
287 1.3 scottr bus_space_write_1(bst, bsh, GC_RESET_OFFSET, 0);
288 1.3 scottr
289 1.10 briggs if (ae_nb_get_enaddr(na, myaddr)) {
290 1.9 scottr /* Fall back to snarf directly from ROM. Ick. */
291 1.9 scottr for (i = 0; i < ETHER_ADDR_LEN; ++i)
292 1.9 scottr myaddr[i] =
293 1.9 scottr bus_space_read_1(bst, bsh,
294 1.9 scottr (GC_ROM_OFFSET + i * 4));
295 1.2 scottr }
296 1.2 scottr
297 1.2 scottr success = 1;
298 1.2 scottr break;
299 1.2 scottr
300 1.3 scottr case AE_VENDOR_KINETICS:
301 1.11 scottr /* Map register offsets */
302 1.11 scottr for (i = 0; i < 16; i++) /* normal order, longword aligned */
303 1.11 scottr sc->sc_reg_map[i] = i << 2;
304 1.11 scottr
305 1.3 scottr sc->use16bit = 0;
306 1.3 scottr if (bus_space_subregion(bst, bsh,
307 1.4 scottr KE_REG_OFFSET, AE_REG_SIZE, &sc->sc_regh)) {
308 1.3 scottr printf(": failed to map register space\n");
309 1.3 scottr break;
310 1.3 scottr }
311 1.3 scottr if ((sc->mem_size = ae_size_card_memory(bst, bsh,
312 1.3 scottr KE_DATA_OFFSET)) == 0) {
313 1.3 scottr printf(": failed to determine size of RAM.\n");
314 1.3 scottr break;
315 1.3 scottr }
316 1.3 scottr if (bus_space_subregion(bst, bsh,
317 1.4 scottr KE_DATA_OFFSET, sc->mem_size, &sc->sc_bufh)) {
318 1.3 scottr printf(": failed to map register space\n");
319 1.3 scottr break;
320 1.3 scottr }
321 1.7 is if (ae_nb_get_enaddr(na, myaddr)) {
322 1.3 scottr printf(": can't find MAC address\n");
323 1.3 scottr break;
324 1.3 scottr }
325 1.3 scottr
326 1.3 scottr success = 1;
327 1.3 scottr break;
328 1.3 scottr
329 1.1 scottr default:
330 1.1 scottr break;
331 1.1 scottr }
332 1.1 scottr
333 1.1 scottr if (!success) {
334 1.1 scottr bus_space_unmap(bst, bsh, NBMEMSIZE);
335 1.1 scottr return;
336 1.1 scottr }
337 1.1 scottr
338 1.11 scottr #ifdef DEBUG
339 1.4 scottr ifp->if_watchdog = ae_nb_watchdog; /* Override watchdog */
340 1.11 scottr #endif
341 1.7 is if (aesetup(sc, myaddr)) {
342 1.5 scottr bus_space_unmap(bst, bsh, NBMEMSIZE);
343 1.5 scottr return;
344 1.5 scottr }
345 1.1 scottr
346 1.1 scottr /* make sure interrupts are vectored to us */
347 1.1 scottr add_nubus_intr(na->slot, aeintr, sc);
348 1.1 scottr }
349 1.1 scottr
350 1.1 scottr static int
351 1.4 scottr ae_nb_card_vendor(na)
352 1.1 scottr struct nubus_attach_args *na;
353 1.1 scottr {
354 1.1 scottr int vendor;
355 1.1 scottr
356 1.1 scottr switch (na->drsw) {
357 1.1 scottr case NUBUS_DRSW_3COM:
358 1.12 briggs switch (na->drhw) {
359 1.12 briggs case NUBUS_DRHW_APPLE_SN:
360 1.12 briggs vendor = AE_VENDOR_UNKNOWN;
361 1.12 briggs break;
362 1.12 briggs default:
363 1.12 briggs vendor = AE_VENDOR_APPLE;
364 1.12 briggs break;
365 1.12 briggs }
366 1.12 briggs break;
367 1.1 scottr case NUBUS_DRSW_APPLE:
368 1.1 scottr case NUBUS_DRSW_TECHWORKS:
369 1.1 scottr vendor = AE_VENDOR_APPLE;
370 1.1 scottr break;
371 1.1 scottr case NUBUS_DRSW_ASANTE:
372 1.1 scottr vendor = AE_VENDOR_ASANTE;
373 1.1 scottr break;
374 1.1 scottr case NUBUS_DRSW_FARALLON:
375 1.1 scottr vendor = AE_VENDOR_FARALLON;
376 1.1 scottr break;
377 1.1 scottr case NUBUS_DRSW_FOCUS:
378 1.1 scottr vendor = AE_VENDOR_FOCUS;
379 1.1 scottr break;
380 1.1 scottr case NUBUS_DRSW_GATOR:
381 1.1 scottr switch (na->drhw) {
382 1.1 scottr default:
383 1.1 scottr case NUBUS_DRHW_INTERLAN:
384 1.1 scottr vendor = AE_VENDOR_INTERLAN;
385 1.1 scottr break;
386 1.1 scottr case NUBUS_DRHW_KINETICS:
387 1.2 scottr if (strncmp(
388 1.2 scottr nubus_get_card_name(na->fmt), "EtherPort", 9) == 0)
389 1.2 scottr vendor = AE_VENDOR_KINETICS;
390 1.2 scottr else
391 1.2 scottr vendor = AE_VENDOR_DAYNA;
392 1.1 scottr break;
393 1.1 scottr }
394 1.1 scottr break;
395 1.1 scottr default:
396 1.1 scottr #ifdef AE_DEBUG
397 1.1 scottr printf("Unknown ethernet drsw: %x\n", na->drsw);
398 1.1 scottr #endif
399 1.1 scottr vendor = AE_VENDOR_UNKNOWN;
400 1.1 scottr }
401 1.1 scottr return vendor;
402 1.3 scottr }
403 1.3 scottr
404 1.3 scottr static int
405 1.4 scottr ae_nb_get_enaddr(na, ep)
406 1.3 scottr struct nubus_attach_args *na;
407 1.3 scottr u_int8_t *ep;
408 1.3 scottr {
409 1.3 scottr nubus_dir dir;
410 1.3 scottr nubus_dirent dirent;
411 1.3 scottr
412 1.3 scottr /*
413 1.3 scottr * XXX - note hardwired resource IDs here (0x80); these are
414 1.3 scottr * assumed to be used by all cards, but should be fixed when
415 1.3 scottr * we find out more about Ethernet card resources.
416 1.3 scottr */
417 1.3 scottr nubus_get_main_dir(na->fmt, &dir);
418 1.3 scottr if (nubus_find_rsrc(na->fmt, &dir, 0x80, &dirent) <= 0)
419 1.3 scottr return 1;
420 1.3 scottr nubus_get_dir_from_rsrc(na->fmt, &dirent, &dir);
421 1.3 scottr if (nubus_find_rsrc(na->fmt, &dir, 0x80, &dirent) <= 0)
422 1.3 scottr return 1;
423 1.3 scottr if (nubus_get_ind_data(na->fmt, &dirent, ep, ETHER_ADDR_LEN) <= 0)
424 1.3 scottr return 1;
425 1.3 scottr
426 1.3 scottr return 0;
427 1.4 scottr }
428 1.4 scottr
429 1.11 scottr #ifdef DEBUG
430 1.4 scottr static void
431 1.4 scottr ae_nb_watchdog(ifp)
432 1.4 scottr struct ifnet *ifp;
433 1.4 scottr {
434 1.4 scottr struct ae_softc *sc = ifp->if_softc;
435 1.4 scottr
436 1.4 scottr /*
437 1.4 scottr * This is a kludge! The via code seems to miss slot interrupts
438 1.4 scottr * sometimes. This kludges around that by calling the handler
439 1.4 scottr * by hand if the watchdog is activated. -- XXX (akb)
440 1.4 scottr */
441 1.4 scottr (*via2itab[1])((void *) 1);
442 1.4 scottr
443 1.4 scottr log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
444 1.7 is ++ifp->if_oerrors;
445 1.4 scottr
446 1.4 scottr aereset(sc);
447 1.1 scottr }
448 1.11 scottr #endif
449