if_ae_nubus.c revision 1.10 1 1.10 briggs /* $NetBSD: if_ae_nubus.c,v 1.10 1997/03/18 00:34:31 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.1 scottr
34 1.1 scottr #include <sys/param.h>
35 1.1 scottr #include <sys/device.h>
36 1.1 scottr #include <sys/errno.h>
37 1.1 scottr #include <sys/ioctl.h>
38 1.1 scottr #include <sys/socket.h>
39 1.4 scottr #include <sys/syslog.h>
40 1.1 scottr #include <sys/systm.h>
41 1.1 scottr
42 1.1 scottr #include <net/if.h>
43 1.7 is #include <net/if_ether.h>
44 1.1 scottr
45 1.1 scottr #ifdef INET
46 1.1 scottr #include <netinet/in.h>
47 1.7 is #include <netinet/if_inarp.h>
48 1.1 scottr #endif
49 1.1 scottr
50 1.1 scottr #include <machine/bus.h>
51 1.1 scottr #include <machine/viareg.h>
52 1.1 scottr
53 1.1 scottr #include "nubus.h"
54 1.1 scottr #include <dev/ic/dp8390reg.h>
55 1.1 scottr #include "if_aereg.h"
56 1.1 scottr #include "if_aevar.h"
57 1.1 scottr
58 1.1 scottr static int ae_nubus_match __P((struct device *, struct cfdata *, void *));
59 1.1 scottr static void ae_nubus_attach __P((struct device *, struct device *, void *));
60 1.4 scottr static int ae_nb_card_vendor __P((struct nubus_attach_args *));
61 1.4 scottr static int ae_nb_get_enaddr __P((struct nubus_attach_args *, u_int8_t *));
62 1.4 scottr static void ae_nb_watchdog __P((struct ifnet *));
63 1.1 scottr
64 1.1 scottr struct cfattach ae_nubus_ca = {
65 1.1 scottr sizeof(struct ae_softc), ae_nubus_match, ae_nubus_attach
66 1.1 scottr };
67 1.1 scottr
68 1.1 scottr static int
69 1.1 scottr ae_nubus_match(parent, cf, aux)
70 1.1 scottr struct device *parent;
71 1.1 scottr struct cfdata *cf;
72 1.1 scottr void *aux;
73 1.1 scottr {
74 1.1 scottr struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
75 1.1 scottr bus_space_handle_t bsh;
76 1.1 scottr int rv;
77 1.1 scottr
78 1.1 scottr if (bus_space_map(na->na_tag, NUBUS_SLOT2PA(na->slot), NBMEMSIZE,
79 1.1 scottr 0, &bsh))
80 1.1 scottr return (0);
81 1.1 scottr
82 1.1 scottr rv = 0;
83 1.1 scottr
84 1.1 scottr if (na->category == NUBUS_CATEGORY_NETWORK &&
85 1.1 scottr na->type == NUBUS_TYPE_ETHERNET) {
86 1.4 scottr switch (ae_nb_card_vendor(na)) {
87 1.1 scottr case AE_VENDOR_APPLE:
88 1.1 scottr case AE_VENDOR_ASANTE:
89 1.1 scottr case AE_VENDOR_FARALLON:
90 1.1 scottr case AE_VENDOR_INTERLAN:
91 1.2 scottr case AE_VENDOR_KINETICS:
92 1.1 scottr rv = 1;
93 1.1 scottr break;
94 1.1 scottr case AE_VENDOR_DAYNA:
95 1.1 scottr case AE_VENDOR_FOCUS:
96 1.1 scottr rv = UNSUPP;
97 1.1 scottr break;
98 1.1 scottr default:
99 1.1 scottr break;
100 1.1 scottr }
101 1.1 scottr }
102 1.1 scottr
103 1.1 scottr bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
104 1.1 scottr
105 1.1 scottr return rv;
106 1.1 scottr }
107 1.1 scottr
108 1.1 scottr /*
109 1.1 scottr * Install interface into kernel networking data structures
110 1.1 scottr */
111 1.1 scottr static void
112 1.1 scottr ae_nubus_attach(parent, self, aux)
113 1.1 scottr struct device *parent, *self;
114 1.1 scottr void *aux;
115 1.1 scottr {
116 1.1 scottr struct ae_softc *sc = (struct ae_softc *) self;
117 1.1 scottr struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
118 1.7 is struct ifnet *ifp = &sc->sc_ec.ec_if;
119 1.1 scottr bus_space_tag_t bst;
120 1.1 scottr bus_space_handle_t bsh;
121 1.10 briggs int i,success;
122 1.7 is u_int8_t myaddr[ETHER_ADDR_LEN];
123 1.1 scottr
124 1.1 scottr bst = na->na_tag;
125 1.1 scottr if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE,
126 1.1 scottr 0, &bsh)) {
127 1.1 scottr printf(": can't map memory space\n");
128 1.1 scottr return;
129 1.1 scottr }
130 1.1 scottr
131 1.4 scottr sc->sc_regt = sc->sc_buft = bst;
132 1.3 scottr sc->sc_flags = self->dv_cfdata->cf_flags;
133 1.1 scottr sc->regs_rev = 0;
134 1.2 scottr sc->use16bit = 1;
135 1.4 scottr sc->vendor = ae_nb_card_vendor(na);
136 1.1 scottr strncpy(sc->type_str, nubus_get_card_name(na->fmt),
137 1.1 scottr INTERFACE_NAME_LEN);
138 1.1 scottr sc->type_str[INTERFACE_NAME_LEN-1] = '\0';
139 1.1 scottr sc->mem_size = 0;
140 1.1 scottr
141 1.1 scottr success = 0;
142 1.1 scottr
143 1.1 scottr switch (sc->vendor) {
144 1.3 scottr case AE_VENDOR_APPLE: /* Apple-compatible cards */
145 1.1 scottr case AE_VENDOR_ASANTE:
146 1.1 scottr sc->regs_rev = 1;
147 1.1 scottr if (bus_space_subregion(bst, bsh,
148 1.4 scottr AE_REG_OFFSET, AE_REG_SIZE, &sc->sc_regh)) {
149 1.1 scottr printf(": failed to map register space\n");
150 1.1 scottr break;
151 1.1 scottr }
152 1.1 scottr if ((sc->mem_size = ae_size_card_memory(bst, bsh,
153 1.1 scottr AE_DATA_OFFSET)) == 0) {
154 1.1 scottr printf(": failed to determine size of RAM.\n");
155 1.1 scottr break;
156 1.1 scottr }
157 1.1 scottr if (bus_space_subregion(bst, bsh,
158 1.4 scottr AE_DATA_OFFSET, sc->mem_size, &sc->sc_bufh)) {
159 1.1 scottr printf(": failed to map register space\n");
160 1.1 scottr break;
161 1.1 scottr }
162 1.3 scottr #ifdef AE_OLD_GET_ENADDR
163 1.1 scottr /* Get station address from on-board ROM */
164 1.1 scottr for (i = 0; i < ETHER_ADDR_LEN; ++i)
165 1.7 is myaddr[i] =
166 1.1 scottr bus_space_read_1(bst, bsh, (AE_ROM_OFFSET + i * 2));
167 1.3 scottr #else
168 1.7 is if (ae_nb_get_enaddr(na, myaddr)) {
169 1.3 scottr printf(": can't find MAC address\n");
170 1.3 scottr break;
171 1.3 scottr }
172 1.3 scottr #endif
173 1.1 scottr
174 1.1 scottr success = 1;
175 1.1 scottr break;
176 1.1 scottr
177 1.1 scottr case AE_VENDOR_DAYNA:
178 1.1 scottr if (bus_space_subregion(bst, bsh,
179 1.4 scottr DP_REG_OFFSET, AE_REG_SIZE, &sc->sc_regh)) {
180 1.1 scottr printf(": failed to map register space\n");
181 1.1 scottr break;
182 1.1 scottr }
183 1.1 scottr sc->mem_size = 8192;
184 1.1 scottr if (bus_space_subregion(bst, bsh,
185 1.4 scottr DP_DATA_OFFSET, sc->mem_size, &sc->sc_bufh)) {
186 1.1 scottr printf(": failed to map register space\n");
187 1.1 scottr break;
188 1.1 scottr }
189 1.3 scottr #ifdef AE_OLD_GET_ENADDR
190 1.1 scottr /* Get station address from on-board ROM */
191 1.1 scottr for (i = 0; i < ETHER_ADDR_LEN; ++i)
192 1.7 is myaddr[i] =
193 1.1 scottr bus_space_read_1(bst, bsh, (DP_ROM_OFFSET + i * 2));
194 1.3 scottr #else
195 1.7 is if (ae_nb_get_enaddr(na, myaddr)) {
196 1.3 scottr printf(": can't find MAC address\n");
197 1.3 scottr break;
198 1.3 scottr }
199 1.3 scottr #endif
200 1.1 scottr
201 1.1 scottr printf(": unsupported Dayna hardware\n");
202 1.1 scottr break;
203 1.1 scottr
204 1.1 scottr case AE_VENDOR_FARALLON:
205 1.1 scottr sc->regs_rev = 1;
206 1.1 scottr if (bus_space_subregion(bst, bsh,
207 1.4 scottr AE_REG_OFFSET, AE_REG_SIZE, &sc->sc_regh)) {
208 1.1 scottr printf(": failed to map register space\n");
209 1.1 scottr break;
210 1.1 scottr }
211 1.1 scottr if ((sc->mem_size = ae_size_card_memory(bst, bsh,
212 1.1 scottr AE_DATA_OFFSET)) == 0) {
213 1.1 scottr printf(": failed to determine size of RAM.\n");
214 1.1 scottr break;
215 1.1 scottr }
216 1.1 scottr if (bus_space_subregion(bst, bsh,
217 1.4 scottr AE_DATA_OFFSET, sc->mem_size, &sc->sc_bufh)) {
218 1.1 scottr printf(": failed to map register space\n");
219 1.1 scottr break;
220 1.1 scottr }
221 1.3 scottr #ifdef AE_OLD_GET_ENADDR
222 1.1 scottr /* Get station address from on-board ROM */
223 1.1 scottr for (i = 0; i < ETHER_ADDR_LEN; ++i)
224 1.7 is myaddr[i] =
225 1.1 scottr bus_space_read_1(bst, bsh, (FE_ROM_OFFSET + i));
226 1.6 scottr #else
227 1.7 is if (ae_nb_get_enaddr(na, myaddr)) {
228 1.6 scottr printf(": can't find MAC address\n");
229 1.6 scottr break;
230 1.6 scottr }
231 1.3 scottr #endif
232 1.1 scottr
233 1.1 scottr success = 1;
234 1.1 scottr break;
235 1.1 scottr
236 1.1 scottr case AE_VENDOR_FOCUS:
237 1.1 scottr printf(": unsupported Focus hardware\n");
238 1.1 scottr break;
239 1.1 scottr
240 1.3 scottr case AE_VENDOR_INTERLAN:
241 1.2 scottr if (bus_space_subregion(bst, bsh,
242 1.4 scottr GC_REG_OFFSET, AE_REG_SIZE, &sc->sc_regh)) {
243 1.2 scottr printf(": failed to map register space\n");
244 1.2 scottr break;
245 1.2 scottr }
246 1.2 scottr if ((sc->mem_size = ae_size_card_memory(bst, bsh,
247 1.3 scottr GC_DATA_OFFSET)) == 0) {
248 1.2 scottr printf(": failed to determine size of RAM.\n");
249 1.2 scottr break;
250 1.2 scottr }
251 1.2 scottr if (bus_space_subregion(bst, bsh,
252 1.4 scottr GC_DATA_OFFSET, sc->mem_size, &sc->sc_bufh)) {
253 1.2 scottr printf(": failed to map register space\n");
254 1.2 scottr break;
255 1.2 scottr }
256 1.2 scottr
257 1.3 scottr /* reset the NIC chip */
258 1.3 scottr bus_space_write_1(bst, bsh, GC_RESET_OFFSET, 0);
259 1.3 scottr
260 1.10 briggs if (ae_nb_get_enaddr(na, myaddr)) {
261 1.9 scottr /* Fall back to snarf directly from ROM. Ick. */
262 1.9 scottr for (i = 0; i < ETHER_ADDR_LEN; ++i)
263 1.9 scottr myaddr[i] =
264 1.9 scottr bus_space_read_1(bst, bsh,
265 1.9 scottr (GC_ROM_OFFSET + i * 4));
266 1.2 scottr }
267 1.2 scottr
268 1.2 scottr success = 1;
269 1.2 scottr break;
270 1.2 scottr
271 1.3 scottr case AE_VENDOR_KINETICS:
272 1.3 scottr sc->use16bit = 0;
273 1.3 scottr if (bus_space_subregion(bst, bsh,
274 1.4 scottr KE_REG_OFFSET, AE_REG_SIZE, &sc->sc_regh)) {
275 1.3 scottr printf(": failed to map register space\n");
276 1.3 scottr break;
277 1.3 scottr }
278 1.3 scottr if ((sc->mem_size = ae_size_card_memory(bst, bsh,
279 1.3 scottr KE_DATA_OFFSET)) == 0) {
280 1.3 scottr printf(": failed to determine size of RAM.\n");
281 1.3 scottr break;
282 1.3 scottr }
283 1.3 scottr if (bus_space_subregion(bst, bsh,
284 1.4 scottr KE_DATA_OFFSET, sc->mem_size, &sc->sc_bufh)) {
285 1.3 scottr printf(": failed to map register space\n");
286 1.3 scottr break;
287 1.3 scottr }
288 1.7 is if (ae_nb_get_enaddr(na, myaddr)) {
289 1.3 scottr printf(": can't find MAC address\n");
290 1.3 scottr break;
291 1.3 scottr }
292 1.3 scottr
293 1.3 scottr success = 1;
294 1.3 scottr break;
295 1.3 scottr
296 1.1 scottr default:
297 1.1 scottr break;
298 1.1 scottr }
299 1.1 scottr
300 1.1 scottr if (!success) {
301 1.1 scottr bus_space_unmap(bst, bsh, NBMEMSIZE);
302 1.1 scottr return;
303 1.1 scottr }
304 1.1 scottr
305 1.4 scottr ifp->if_watchdog = ae_nb_watchdog; /* Override watchdog */
306 1.7 is if (aesetup(sc, myaddr)) {
307 1.5 scottr bus_space_unmap(bst, bsh, NBMEMSIZE);
308 1.5 scottr return;
309 1.5 scottr }
310 1.1 scottr
311 1.1 scottr /* make sure interrupts are vectored to us */
312 1.1 scottr add_nubus_intr(na->slot, aeintr, sc);
313 1.1 scottr }
314 1.1 scottr
315 1.1 scottr static int
316 1.4 scottr ae_nb_card_vendor(na)
317 1.1 scottr struct nubus_attach_args *na;
318 1.1 scottr {
319 1.1 scottr int vendor;
320 1.1 scottr
321 1.1 scottr switch (na->drsw) {
322 1.1 scottr case NUBUS_DRSW_3COM:
323 1.1 scottr case NUBUS_DRSW_APPLE:
324 1.1 scottr case NUBUS_DRSW_TECHWORKS:
325 1.1 scottr vendor = AE_VENDOR_APPLE;
326 1.1 scottr break;
327 1.1 scottr case NUBUS_DRSW_ASANTE:
328 1.1 scottr vendor = AE_VENDOR_ASANTE;
329 1.1 scottr break;
330 1.1 scottr case NUBUS_DRSW_FARALLON:
331 1.1 scottr vendor = AE_VENDOR_FARALLON;
332 1.1 scottr break;
333 1.1 scottr case NUBUS_DRSW_FOCUS:
334 1.1 scottr vendor = AE_VENDOR_FOCUS;
335 1.1 scottr break;
336 1.1 scottr case NUBUS_DRSW_GATOR:
337 1.1 scottr switch (na->drhw) {
338 1.1 scottr default:
339 1.1 scottr case NUBUS_DRHW_INTERLAN:
340 1.1 scottr vendor = AE_VENDOR_INTERLAN;
341 1.1 scottr break;
342 1.1 scottr case NUBUS_DRHW_KINETICS:
343 1.2 scottr if (strncmp(
344 1.2 scottr nubus_get_card_name(na->fmt), "EtherPort", 9) == 0)
345 1.2 scottr vendor = AE_VENDOR_KINETICS;
346 1.2 scottr else
347 1.2 scottr vendor = AE_VENDOR_DAYNA;
348 1.1 scottr break;
349 1.1 scottr }
350 1.1 scottr break;
351 1.1 scottr default:
352 1.1 scottr #ifdef AE_DEBUG
353 1.1 scottr printf("Unknown ethernet drsw: %x\n", na->drsw);
354 1.1 scottr #endif
355 1.1 scottr vendor = AE_VENDOR_UNKNOWN;
356 1.1 scottr }
357 1.1 scottr return vendor;
358 1.3 scottr }
359 1.3 scottr
360 1.3 scottr static int
361 1.4 scottr ae_nb_get_enaddr(na, ep)
362 1.3 scottr struct nubus_attach_args *na;
363 1.3 scottr u_int8_t *ep;
364 1.3 scottr {
365 1.3 scottr nubus_dir dir;
366 1.3 scottr nubus_dirent dirent;
367 1.3 scottr
368 1.3 scottr /*
369 1.3 scottr * XXX - note hardwired resource IDs here (0x80); these are
370 1.3 scottr * assumed to be used by all cards, but should be fixed when
371 1.3 scottr * we find out more about Ethernet card resources.
372 1.3 scottr */
373 1.3 scottr nubus_get_main_dir(na->fmt, &dir);
374 1.3 scottr if (nubus_find_rsrc(na->fmt, &dir, 0x80, &dirent) <= 0)
375 1.3 scottr return 1;
376 1.3 scottr nubus_get_dir_from_rsrc(na->fmt, &dirent, &dir);
377 1.3 scottr if (nubus_find_rsrc(na->fmt, &dir, 0x80, &dirent) <= 0)
378 1.3 scottr return 1;
379 1.3 scottr if (nubus_get_ind_data(na->fmt, &dirent, ep, ETHER_ADDR_LEN) <= 0)
380 1.3 scottr return 1;
381 1.3 scottr
382 1.3 scottr return 0;
383 1.4 scottr }
384 1.4 scottr
385 1.4 scottr static void
386 1.4 scottr ae_nb_watchdog(ifp)
387 1.4 scottr struct ifnet *ifp;
388 1.4 scottr {
389 1.4 scottr struct ae_softc *sc = ifp->if_softc;
390 1.4 scottr
391 1.4 scottr #if 1
392 1.4 scottr /*
393 1.4 scottr * This is a kludge! The via code seems to miss slot interrupts
394 1.4 scottr * sometimes. This kludges around that by calling the handler
395 1.4 scottr * by hand if the watchdog is activated. -- XXX (akb)
396 1.4 scottr */
397 1.4 scottr (*via2itab[1])((void *) 1);
398 1.4 scottr #endif
399 1.4 scottr
400 1.4 scottr log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
401 1.7 is ++ifp->if_oerrors;
402 1.4 scottr
403 1.4 scottr aereset(sc);
404 1.1 scottr }
405