if_ae_nubus.c revision 1.2 1 1.2 scottr /* $NetBSD: if_ae_nubus.c,v 1.2 1997/02/24 07:34:19 scottr 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 "bpfilter.h"
35 1.1 scottr
36 1.1 scottr #include <sys/param.h>
37 1.1 scottr #include <sys/device.h>
38 1.1 scottr #include <sys/errno.h>
39 1.1 scottr #include <sys/ioctl.h>
40 1.1 scottr #include <sys/socket.h>
41 1.1 scottr #include <sys/systm.h>
42 1.1 scottr
43 1.1 scottr #include <net/if.h>
44 1.1 scottr #include <net/if_dl.h>
45 1.1 scottr #include <net/if_types.h>
46 1.1 scottr #include <net/netisr.h>
47 1.1 scottr
48 1.1 scottr #ifdef INET
49 1.1 scottr #include <netinet/in.h>
50 1.1 scottr #include <netinet/in_systm.h>
51 1.1 scottr #include <netinet/in_var.h>
52 1.1 scottr #include <netinet/ip.h>
53 1.1 scottr #include <netinet/if_ether.h>
54 1.1 scottr #endif
55 1.1 scottr
56 1.1 scottr #ifdef NS
57 1.1 scottr #include <netns/ns.h>
58 1.1 scottr #include <netns/ns_if.h>
59 1.1 scottr #endif
60 1.1 scottr
61 1.1 scottr #if NBPFILTER > 0
62 1.1 scottr #include <net/bpf.h>
63 1.1 scottr #include <net/bpfdesc.h>
64 1.1 scottr #endif
65 1.1 scottr
66 1.1 scottr #include <machine/bus.h>
67 1.1 scottr #include <machine/viareg.h>
68 1.1 scottr
69 1.1 scottr #include "nubus.h"
70 1.1 scottr #include <dev/ic/dp8390reg.h>
71 1.1 scottr #include "if_aereg.h"
72 1.1 scottr #include "if_aevar.h"
73 1.1 scottr
74 1.1 scottr static int ae_nubus_match __P((struct device *, struct cfdata *, void *));
75 1.1 scottr static void ae_nubus_attach __P((struct device *, struct device *, void *));
76 1.1 scottr static int ae_card_vendor __P((struct nubus_attach_args *na));
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.1 scottr switch (ae_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.1 scottr struct ifnet *ifp = &sc->sc_arpcom.ac_if;
133 1.1 scottr bus_space_tag_t bst;
134 1.1 scottr bus_space_handle_t bsh;
135 1.1 scottr int i, success;
136 1.1 scottr int flags = 0;
137 1.1 scottr
138 1.1 scottr bst = na->na_tag;
139 1.1 scottr if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE,
140 1.1 scottr 0, &bsh)) {
141 1.1 scottr printf(": can't map memory space\n");
142 1.1 scottr return;
143 1.1 scottr }
144 1.1 scottr
145 1.1 scottr sc->regs_rev = 0;
146 1.2 scottr sc->use16bit = 1;
147 1.1 scottr sc->vendor = ae_card_vendor(na);
148 1.1 scottr strncpy(sc->type_str, nubus_get_card_name(na->fmt),
149 1.1 scottr INTERFACE_NAME_LEN);
150 1.1 scottr sc->type_str[INTERFACE_NAME_LEN-1] = '\0';
151 1.1 scottr sc->mem_size = 0;
152 1.1 scottr
153 1.1 scottr success = 0;
154 1.1 scottr
155 1.1 scottr switch (sc->vendor) {
156 1.1 scottr case AE_VENDOR_INTERLAN:
157 1.1 scottr if (bus_space_subregion(bst, bsh,
158 1.1 scottr GC_REG_OFFSET, AE_REG_SIZE, &sc->sc_reg_handle)) {
159 1.1 scottr printf(": failed to map register space\n");
160 1.1 scottr break;
161 1.1 scottr }
162 1.1 scottr if ((sc->mem_size = ae_size_card_memory(bst, bsh,
163 1.1 scottr GC_DATA_OFFSET)) == 0) {
164 1.1 scottr printf(": failed to determine size of RAM.\n");
165 1.1 scottr break;
166 1.1 scottr }
167 1.1 scottr if (bus_space_subregion(bst, bsh,
168 1.1 scottr GC_DATA_OFFSET, sc->mem_size, &sc->sc_buf_handle)) {
169 1.1 scottr printf(": failed to map register space\n");
170 1.1 scottr break;
171 1.1 scottr }
172 1.1 scottr
173 1.1 scottr /* reset the NIC chip */
174 1.1 scottr bus_space_write_1(bst, bsh, GC_RESET_OFFSET, 0);
175 1.1 scottr
176 1.1 scottr /* Get station address from on-board ROM */
177 1.1 scottr for (i = 0; i < ETHER_ADDR_LEN; ++i)
178 1.1 scottr sc->sc_arpcom.ac_enaddr[i] =
179 1.1 scottr bus_space_read_1(bst, bsh, (GC_ROM_OFFSET + i * 4));
180 1.1 scottr
181 1.1 scottr success = 1;
182 1.1 scottr break;
183 1.1 scottr
184 1.1 scottr /* Apple-compatible cards */
185 1.1 scottr case AE_VENDOR_ASANTE:
186 1.1 scottr case AE_VENDOR_APPLE:
187 1.1 scottr sc->regs_rev = 1;
188 1.1 scottr if (bus_space_subregion(bst, bsh,
189 1.1 scottr AE_REG_OFFSET, AE_REG_SIZE, &sc->sc_reg_handle)) {
190 1.1 scottr printf(": failed to map register space\n");
191 1.1 scottr break;
192 1.1 scottr }
193 1.1 scottr if ((sc->mem_size = ae_size_card_memory(bst, bsh,
194 1.1 scottr AE_DATA_OFFSET)) == 0) {
195 1.1 scottr printf(": failed to determine size of RAM.\n");
196 1.1 scottr break;
197 1.1 scottr }
198 1.1 scottr if (bus_space_subregion(bst, bsh,
199 1.1 scottr AE_DATA_OFFSET, sc->mem_size, &sc->sc_buf_handle)) {
200 1.1 scottr printf(": failed to map register space\n");
201 1.1 scottr break;
202 1.1 scottr }
203 1.1 scottr
204 1.1 scottr /* Get station address from on-board ROM */
205 1.1 scottr for (i = 0; i < ETHER_ADDR_LEN; ++i)
206 1.1 scottr sc->sc_arpcom.ac_enaddr[i] =
207 1.1 scottr bus_space_read_1(bst, bsh, (AE_ROM_OFFSET + i * 2));
208 1.1 scottr
209 1.1 scottr success = 1;
210 1.1 scottr break;
211 1.1 scottr
212 1.1 scottr case AE_VENDOR_DAYNA:
213 1.1 scottr if (bus_space_subregion(bst, bsh,
214 1.1 scottr DP_REG_OFFSET, AE_REG_SIZE, &sc->sc_reg_handle)) {
215 1.1 scottr printf(": failed to map register space\n");
216 1.1 scottr break;
217 1.1 scottr }
218 1.1 scottr sc->mem_size = 8192;
219 1.1 scottr if (bus_space_subregion(bst, bsh,
220 1.1 scottr DP_DATA_OFFSET, sc->mem_size, &sc->sc_buf_handle)) {
221 1.1 scottr printf(": failed to map register space\n");
222 1.1 scottr break;
223 1.1 scottr }
224 1.1 scottr
225 1.1 scottr /* Get station address from on-board ROM */
226 1.1 scottr for (i = 0; i < ETHER_ADDR_LEN; ++i)
227 1.1 scottr sc->sc_arpcom.ac_enaddr[i] =
228 1.1 scottr bus_space_read_1(bst, bsh, (DP_ROM_OFFSET + i * 2));
229 1.1 scottr
230 1.1 scottr printf(": unsupported Dayna hardware\n");
231 1.1 scottr break;
232 1.1 scottr
233 1.1 scottr case AE_VENDOR_FARALLON:
234 1.1 scottr sc->regs_rev = 1;
235 1.1 scottr if (bus_space_subregion(bst, bsh,
236 1.1 scottr AE_REG_OFFSET, AE_REG_SIZE, &sc->sc_reg_handle)) {
237 1.1 scottr printf(": failed to map register space\n");
238 1.1 scottr break;
239 1.1 scottr }
240 1.1 scottr if ((sc->mem_size = ae_size_card_memory(bst, bsh,
241 1.1 scottr AE_DATA_OFFSET)) == 0) {
242 1.1 scottr printf(": failed to determine size of RAM.\n");
243 1.1 scottr break;
244 1.1 scottr }
245 1.1 scottr if (bus_space_subregion(bst, bsh,
246 1.1 scottr AE_DATA_OFFSET, sc->mem_size, &sc->sc_buf_handle)) {
247 1.1 scottr printf(": failed to map register space\n");
248 1.1 scottr break;
249 1.1 scottr }
250 1.1 scottr
251 1.1 scottr /* Get station address from on-board ROM */
252 1.1 scottr for (i = 0; i < ETHER_ADDR_LEN; ++i)
253 1.1 scottr sc->sc_arpcom.ac_enaddr[i] =
254 1.1 scottr bus_space_read_1(bst, bsh, (FE_ROM_OFFSET + i));
255 1.1 scottr
256 1.1 scottr success = 1;
257 1.1 scottr break;
258 1.1 scottr
259 1.1 scottr case AE_VENDOR_FOCUS:
260 1.1 scottr printf(": unsupported Focus hardware\n");
261 1.1 scottr break;
262 1.1 scottr
263 1.2 scottr case AE_VENDOR_KINETICS:
264 1.2 scottr sc->use16bit = 0;
265 1.2 scottr if (bus_space_subregion(bst, bsh,
266 1.2 scottr KE_REG_OFFSET, AE_REG_SIZE, &sc->sc_reg_handle)) {
267 1.2 scottr printf(": failed to map register space\n");
268 1.2 scottr break;
269 1.2 scottr }
270 1.2 scottr if ((sc->mem_size = ae_size_card_memory(bst, bsh,
271 1.2 scottr KE_DATA_OFFSET)) == 0) {
272 1.2 scottr printf(": failed to determine size of RAM.\n");
273 1.2 scottr break;
274 1.2 scottr }
275 1.2 scottr if (bus_space_subregion(bst, bsh,
276 1.2 scottr KE_DATA_OFFSET, sc->mem_size, &sc->sc_buf_handle)) {
277 1.2 scottr printf(": failed to map register space\n");
278 1.2 scottr break;
279 1.2 scottr }
280 1.2 scottr
281 1.2 scottr /* Get station address from on-board ROM */
282 1.2 scottr #if 0
283 1.2 scottr for (i = 0; i < ETHER_ADDR_LEN; ++i)
284 1.2 scottr sc->sc_arpcom.ac_enaddr[i] =
285 1.2 scottr bus_space_read_1(bst, bsh, (KE_ROM_OFFSET + i));
286 1.2 scottr #else
287 1.2 scottr {
288 1.2 scottr nubus_dir dir;
289 1.2 scottr nubus_dirent dirent;
290 1.2 scottr
291 1.2 scottr /* getting the MAC address */
292 1.2 scottr nubus_get_main_dir(na->fmt, &dir);
293 1.2 scottr if (nubus_find_rsrc(na->fmt, &dir, 0x80, &dirent) <= 0)
294 1.2 scottr break;
295 1.2 scottr nubus_get_dir_from_rsrc(na->fmt, &dirent, &dir);
296 1.2 scottr if (nubus_find_rsrc(na->fmt, &dir, 0x80, &dirent) <= 0)
297 1.2 scottr break;
298 1.2 scottr if (nubus_get_ind_data(na->fmt, &dirent,
299 1.2 scottr (caddr_t)sc->sc_arpcom.ac_enaddr,
300 1.2 scottr ETHER_ADDR_LEN) <= 0)
301 1.2 scottr break;
302 1.2 scottr }
303 1.2 scottr #endif
304 1.2 scottr
305 1.2 scottr success = 1;
306 1.2 scottr break;
307 1.2 scottr
308 1.1 scottr default:
309 1.1 scottr break;
310 1.1 scottr }
311 1.1 scottr
312 1.1 scottr if (!success) {
313 1.1 scottr bus_space_unmap(bst, bsh, NBMEMSIZE);
314 1.1 scottr return;
315 1.1 scottr }
316 1.1 scottr
317 1.1 scottr sc->sc_reg_tag = sc->sc_buf_tag = bst;
318 1.1 scottr
319 1.1 scottr sc->cr_proto = ED_CR_RD2;
320 1.1 scottr
321 1.1 scottr /* Allocate one xmit buffer if < 16k, two buffers otherwise. */
322 1.1 scottr if ((sc->mem_size < 16384) || (flags & AE_FLAGS_NO_DOUBLE_BUFFERING))
323 1.1 scottr sc->txb_cnt = 1;
324 1.1 scottr else
325 1.1 scottr sc->txb_cnt = 2;
326 1.1 scottr
327 1.1 scottr sc->tx_page_start = 0;
328 1.1 scottr sc->rec_page_start = sc->tx_page_start + sc->txb_cnt * ED_TXBUF_SIZE;
329 1.1 scottr sc->rec_page_stop = sc->tx_page_start + (sc->mem_size >> ED_PAGE_SHIFT);
330 1.1 scottr sc->mem_ring = sc->rec_page_start << ED_PAGE_SHIFT;
331 1.1 scottr
332 1.1 scottr /* Now zero memory and verify that it is clear. */
333 1.1 scottr bus_space_set_region_2(sc->sc_buf_tag, sc->sc_buf_handle, 0,
334 1.1 scottr 0, sc->mem_size / 2);
335 1.1 scottr
336 1.1 scottr for (i = 0; i < sc->mem_size; ++i)
337 1.1 scottr if (bus_space_read_1(sc->sc_buf_tag, sc->sc_buf_handle, i))
338 1.1 scottr printf("%s: failed to clear shared memory - check configuration\n",
339 1.1 scottr sc->sc_dev.dv_xname);
340 1.1 scottr
341 1.1 scottr /* Set interface to stopped condition (reset). */
342 1.1 scottr aestop(sc);
343 1.1 scottr
344 1.1 scottr /* Initialize ifnet structure. */
345 1.1 scottr bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
346 1.1 scottr ifp->if_softc = sc;
347 1.1 scottr ifp->if_start = aestart;
348 1.1 scottr ifp->if_ioctl = aeioctl;
349 1.1 scottr ifp->if_watchdog = aewatchdog;
350 1.1 scottr ifp->if_flags =
351 1.1 scottr IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
352 1.1 scottr
353 1.1 scottr /* Attach the interface. */
354 1.1 scottr if_attach(ifp);
355 1.1 scottr ether_ifattach(ifp);
356 1.1 scottr
357 1.1 scottr /* Print additional info when attached. */
358 1.1 scottr printf(": address %s, ", ether_sprintf(sc->sc_arpcom.ac_enaddr));
359 1.1 scottr
360 1.1 scottr printf("type %s, %dKB memory\n", sc->type_str, sc->mem_size / 1024);
361 1.1 scottr
362 1.1 scottr #if NBPFILTER > 0
363 1.1 scottr bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
364 1.1 scottr #endif
365 1.1 scottr
366 1.1 scottr /* make sure interrupts are vectored to us */
367 1.1 scottr add_nubus_intr(na->slot, aeintr, sc);
368 1.1 scottr
369 1.1 scottr /*
370 1.1 scottr * XXX -- enable nubus interrupts here. Should be done elsewhere,
371 1.1 scottr * but that currently breaks with some nubus video cards'
372 1.1 scottr * interrupts. So we only enable nubus interrupts if we
373 1.1 scottr * have an ethernet card... i.e., we do it here.
374 1.1 scottr */
375 1.1 scottr enable_nubus_intr();
376 1.1 scottr }
377 1.1 scottr
378 1.1 scottr static int
379 1.1 scottr ae_card_vendor(na)
380 1.1 scottr struct nubus_attach_args *na;
381 1.1 scottr {
382 1.1 scottr int vendor;
383 1.1 scottr
384 1.1 scottr switch (na->drsw) {
385 1.1 scottr case NUBUS_DRSW_3COM:
386 1.1 scottr case NUBUS_DRSW_APPLE:
387 1.1 scottr case NUBUS_DRSW_TECHWORKS:
388 1.1 scottr vendor = AE_VENDOR_APPLE;
389 1.1 scottr break;
390 1.1 scottr case NUBUS_DRSW_ASANTE:
391 1.1 scottr vendor = AE_VENDOR_ASANTE;
392 1.1 scottr break;
393 1.1 scottr case NUBUS_DRSW_FARALLON:
394 1.1 scottr vendor = AE_VENDOR_FARALLON;
395 1.1 scottr break;
396 1.1 scottr case NUBUS_DRSW_FOCUS:
397 1.1 scottr vendor = AE_VENDOR_FOCUS;
398 1.1 scottr break;
399 1.1 scottr case NUBUS_DRSW_GATOR:
400 1.1 scottr switch (na->drhw) {
401 1.1 scottr default:
402 1.1 scottr case NUBUS_DRHW_INTERLAN:
403 1.1 scottr vendor = AE_VENDOR_INTERLAN;
404 1.1 scottr break;
405 1.1 scottr case NUBUS_DRHW_KINETICS:
406 1.2 scottr if (strncmp(
407 1.2 scottr nubus_get_card_name(na->fmt), "EtherPort", 9) == 0)
408 1.2 scottr vendor = AE_VENDOR_KINETICS;
409 1.2 scottr else
410 1.2 scottr vendor = AE_VENDOR_DAYNA;
411 1.1 scottr break;
412 1.1 scottr }
413 1.1 scottr break;
414 1.1 scottr default:
415 1.1 scottr #ifdef AE_DEBUG
416 1.1 scottr printf("Unknown ethernet drsw: %x\n", na->drsw);
417 1.1 scottr #endif
418 1.1 scottr vendor = AE_VENDOR_UNKNOWN;
419 1.1 scottr }
420 1.1 scottr return vendor;
421 1.1 scottr }
422