if_ie_obio.c revision 1.2.4.2 1 1.2.4.2 nathanw /* $NetBSD: if_ie_obio.c,v 1.2.4.2 2002/10/18 02:40:14 nathanw Exp $ */
2 1.2.4.2 nathanw
3 1.2.4.2 nathanw /*-
4 1.2.4.2 nathanw * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 1.2.4.2 nathanw * All rights reserved.
6 1.2.4.2 nathanw *
7 1.2.4.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.2.4.2 nathanw * by Paul Kranenburg and Matt Fredette.
9 1.2.4.2 nathanw *
10 1.2.4.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.2.4.2 nathanw * modification, are permitted provided that the following conditions
12 1.2.4.2 nathanw * are met:
13 1.2.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.2.4.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.2.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.2.4.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.2.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.2.4.2 nathanw * must display the following acknowledgement:
20 1.2.4.2 nathanw * This product includes software developed by the NetBSD
21 1.2.4.2 nathanw * Foundation, Inc. and its contributors.
22 1.2.4.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.4.2 nathanw * contributors may be used to endorse or promote products derived
24 1.2.4.2 nathanw * from this software without specific prior written permission.
25 1.2.4.2 nathanw *
26 1.2.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.4.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.4.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.4.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.4.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.4.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.4.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.4.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.4.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.4.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.4.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.2.4.2 nathanw */
38 1.2.4.2 nathanw
39 1.2.4.2 nathanw /*-
40 1.2.4.2 nathanw * Copyright (c) 1995 Charles D. Cranor
41 1.2.4.2 nathanw * All rights reserved.
42 1.2.4.2 nathanw *
43 1.2.4.2 nathanw * Redistribution and use in source and binary forms, with or without
44 1.2.4.2 nathanw * modification, are permitted provided that the following conditions
45 1.2.4.2 nathanw * are met:
46 1.2.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
47 1.2.4.2 nathanw * notice, this list of conditions and the following disclaimer.
48 1.2.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
49 1.2.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
50 1.2.4.2 nathanw * documentation and/or other materials provided with the distribution.
51 1.2.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
52 1.2.4.2 nathanw * must display the following acknowledgement:
53 1.2.4.2 nathanw * This product includes software developed by Charles D. Cranor.
54 1.2.4.2 nathanw * 4. The name of the author may not be used to endorse or promote products
55 1.2.4.2 nathanw * derived from this software without specific prior written permission.
56 1.2.4.2 nathanw *
57 1.2.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
58 1.2.4.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 1.2.4.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 1.2.4.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
61 1.2.4.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
62 1.2.4.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63 1.2.4.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64 1.2.4.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 1.2.4.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
66 1.2.4.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 1.2.4.2 nathanw */
68 1.2.4.2 nathanw
69 1.2.4.2 nathanw
70 1.2.4.2 nathanw
71 1.2.4.2 nathanw /*
72 1.2.4.2 nathanw * Sun2 OBIO front-end for the Intel 82586 Ethernet driver
73 1.2.4.2 nathanw *
74 1.2.4.2 nathanw * Converted to SUN ie driver by Charles D. Cranor,
75 1.2.4.2 nathanw * October 1994, January 1995.
76 1.2.4.2 nathanw */
77 1.2.4.2 nathanw
78 1.2.4.2 nathanw /*
79 1.2.4.2 nathanw * The i82586 is a very painful chip, found in sun[23]'s, sun-4/100's
80 1.2.4.2 nathanw * sun-4/200's, and VME based suns. The byte order is all wrong for a
81 1.2.4.2 nathanw * SUN, making life difficult. Programming this chip is mostly the same,
82 1.2.4.2 nathanw * but certain details differ from system to system. This driver is
83 1.2.4.2 nathanw * written so that different "ie" interfaces can be controled by the same
84 1.2.4.2 nathanw * driver.
85 1.2.4.2 nathanw */
86 1.2.4.2 nathanw
87 1.2.4.2 nathanw #include <sys/param.h>
88 1.2.4.2 nathanw #include <sys/systm.h>
89 1.2.4.2 nathanw #include <sys/errno.h>
90 1.2.4.2 nathanw #include <sys/device.h>
91 1.2.4.2 nathanw #include <sys/malloc.h>
92 1.2.4.2 nathanw #include <sys/protosw.h>
93 1.2.4.2 nathanw #include <sys/socket.h>
94 1.2.4.2 nathanw
95 1.2.4.2 nathanw #include <net/if.h>
96 1.2.4.2 nathanw #include <net/if_types.h>
97 1.2.4.2 nathanw #include <net/if_dl.h>
98 1.2.4.2 nathanw #include <net/if_media.h>
99 1.2.4.2 nathanw #include <net/if_ether.h>
100 1.2.4.2 nathanw
101 1.2.4.2 nathanw #include <uvm/uvm_extern.h>
102 1.2.4.2 nathanw
103 1.2.4.2 nathanw #include <machine/bus.h>
104 1.2.4.2 nathanw #include <machine/intr.h>
105 1.2.4.2 nathanw #include <machine/autoconf.h>
106 1.2.4.2 nathanw #include <machine/idprom.h>
107 1.2.4.2 nathanw
108 1.2.4.2 nathanw #include <dev/ic/i82586reg.h>
109 1.2.4.2 nathanw #include <dev/ic/i82586var.h>
110 1.2.4.2 nathanw
111 1.2.4.2 nathanw /*
112 1.2.4.2 nathanw * the on-board interface
113 1.2.4.2 nathanw */
114 1.2.4.2 nathanw struct ieob {
115 1.2.4.2 nathanw u_char obctrl;
116 1.2.4.2 nathanw };
117 1.2.4.2 nathanw #define IEOB_NORSET 0x80 /* don't reset the board */
118 1.2.4.2 nathanw #define IEOB_ONAIR 0x40 /* put us on the air */
119 1.2.4.2 nathanw #define IEOB_ATTEN 0x20 /* attention! */
120 1.2.4.2 nathanw #define IEOB_IENAB 0x10 /* interrupt enable */
121 1.2.4.2 nathanw #define IEOB_XXXXX 0x08 /* free bit */
122 1.2.4.2 nathanw #define IEOB_XCVRL2 0x04 /* level 2 transceiver? */
123 1.2.4.2 nathanw #define IEOB_BUSERR 0x02 /* bus error */
124 1.2.4.2 nathanw #define IEOB_INT 0x01 /* interrupt */
125 1.2.4.2 nathanw
126 1.2.4.2 nathanw #define IEOB_ADBASE 0x000000 /* KVA base addr of 24 bit address space */
127 1.2.4.2 nathanw
128 1.2.4.2 nathanw
129 1.2.4.2 nathanw static void ie_obreset __P((struct ie_softc *, int));
130 1.2.4.2 nathanw static void ie_obattend __P((struct ie_softc *, int));
131 1.2.4.2 nathanw static void ie_obrun __P((struct ie_softc *));
132 1.2.4.2 nathanw
133 1.2.4.2 nathanw int ie_obio_match __P((struct device *, struct cfdata *, void *));
134 1.2.4.2 nathanw void ie_obio_attach __P((struct device *, struct device *, void *));
135 1.2.4.2 nathanw
136 1.2.4.2 nathanw CFATTACH_DECL(ie_obio, sizeof(struct ie_softc),
137 1.2.4.2 nathanw ie_obio_match, ie_obio_attach, NULL, NULL);
138 1.2.4.2 nathanw
139 1.2.4.2 nathanw /* Supported media */
140 1.2.4.2 nathanw static int media[] = {
141 1.2.4.2 nathanw IFM_ETHER | IFM_10_2,
142 1.2.4.2 nathanw };
143 1.2.4.2 nathanw #define NMEDIA (sizeof(media) / sizeof(media[0]))
144 1.2.4.2 nathanw
145 1.2.4.2 nathanw
146 1.2.4.2 nathanw /*
147 1.2.4.2 nathanw * OBIO ie support routines
148 1.2.4.2 nathanw */
149 1.2.4.2 nathanw void
150 1.2.4.2 nathanw ie_obreset(sc, what)
151 1.2.4.2 nathanw struct ie_softc *sc;
152 1.2.4.2 nathanw {
153 1.2.4.2 nathanw volatile struct ieob *ieo = (struct ieob *) sc->sc_reg;
154 1.2.4.2 nathanw ieo->obctrl = 0;
155 1.2.4.2 nathanw delay(100); /* XXX could be shorter? */
156 1.2.4.2 nathanw ieo->obctrl = IEOB_NORSET;
157 1.2.4.2 nathanw }
158 1.2.4.2 nathanw void
159 1.2.4.2 nathanw ie_obattend(sc, why)
160 1.2.4.2 nathanw struct ie_softc *sc;
161 1.2.4.2 nathanw int why;
162 1.2.4.2 nathanw {
163 1.2.4.2 nathanw volatile struct ieob *ieo = (struct ieob *) sc->sc_reg;
164 1.2.4.2 nathanw
165 1.2.4.2 nathanw ieo->obctrl |= IEOB_ATTEN; /* flag! */
166 1.2.4.2 nathanw ieo->obctrl &= ~IEOB_ATTEN; /* down. */
167 1.2.4.2 nathanw }
168 1.2.4.2 nathanw
169 1.2.4.2 nathanw void
170 1.2.4.2 nathanw ie_obrun(sc)
171 1.2.4.2 nathanw struct ie_softc *sc;
172 1.2.4.2 nathanw {
173 1.2.4.2 nathanw volatile struct ieob *ieo = (struct ieob *) sc->sc_reg;
174 1.2.4.2 nathanw
175 1.2.4.2 nathanw ieo->obctrl |= (IEOB_ONAIR|IEOB_IENAB|IEOB_NORSET);
176 1.2.4.2 nathanw }
177 1.2.4.2 nathanw
178 1.2.4.2 nathanw void ie_obio_memcopyin __P((struct ie_softc *, void *, int, size_t));
179 1.2.4.2 nathanw void ie_obio_memcopyout __P((struct ie_softc *, const void *, int, size_t));
180 1.2.4.2 nathanw
181 1.2.4.2 nathanw /*
182 1.2.4.2 nathanw * Copy board memory to kernel.
183 1.2.4.2 nathanw */
184 1.2.4.2 nathanw void
185 1.2.4.2 nathanw ie_obio_memcopyin(sc, p, offset, size)
186 1.2.4.2 nathanw struct ie_softc *sc;
187 1.2.4.2 nathanw void *p;
188 1.2.4.2 nathanw int offset;
189 1.2.4.2 nathanw size_t size;
190 1.2.4.2 nathanw {
191 1.2.4.2 nathanw bus_space_copyin(sc->bt, sc->bh, offset, p, size);
192 1.2.4.2 nathanw }
193 1.2.4.2 nathanw
194 1.2.4.2 nathanw /*
195 1.2.4.2 nathanw * Copy from kernel space to naord memory.
196 1.2.4.2 nathanw */
197 1.2.4.2 nathanw void
198 1.2.4.2 nathanw ie_obio_memcopyout(sc, p, offset, size)
199 1.2.4.2 nathanw struct ie_softc *sc;
200 1.2.4.2 nathanw const void *p;
201 1.2.4.2 nathanw int offset;
202 1.2.4.2 nathanw size_t size;
203 1.2.4.2 nathanw {
204 1.2.4.2 nathanw bus_space_copyout(sc->bt, sc->bh, offset, p, size);
205 1.2.4.2 nathanw }
206 1.2.4.2 nathanw
207 1.2.4.2 nathanw /* read a 16-bit value at BH offset */
208 1.2.4.2 nathanw u_int16_t ie_obio_read16 __P((struct ie_softc *, int offset));
209 1.2.4.2 nathanw /* write a 16-bit value at BH offset */
210 1.2.4.2 nathanw void ie_obio_write16 __P((struct ie_softc *, int offset, u_int16_t value));
211 1.2.4.2 nathanw void ie_obio_write24 __P((struct ie_softc *, int offset, int addr));
212 1.2.4.2 nathanw
213 1.2.4.2 nathanw u_int16_t
214 1.2.4.2 nathanw ie_obio_read16(sc, offset)
215 1.2.4.2 nathanw struct ie_softc *sc;
216 1.2.4.2 nathanw int offset;
217 1.2.4.2 nathanw {
218 1.2.4.2 nathanw u_int16_t v = bus_space_read_2(sc->bt, sc->bh, offset);
219 1.2.4.2 nathanw return (((v&0xff)<<8) | ((v>>8)&0xff));
220 1.2.4.2 nathanw }
221 1.2.4.2 nathanw
222 1.2.4.2 nathanw void
223 1.2.4.2 nathanw ie_obio_write16(sc, offset, v)
224 1.2.4.2 nathanw struct ie_softc *sc;
225 1.2.4.2 nathanw int offset;
226 1.2.4.2 nathanw u_int16_t v;
227 1.2.4.2 nathanw {
228 1.2.4.2 nathanw v = (((v&0xff)<<8) | ((v>>8)&0xff));
229 1.2.4.2 nathanw bus_space_write_2(sc->bt, sc->bh, offset, v);
230 1.2.4.2 nathanw }
231 1.2.4.2 nathanw
232 1.2.4.2 nathanw void
233 1.2.4.2 nathanw ie_obio_write24(sc, offset, addr)
234 1.2.4.2 nathanw struct ie_softc *sc;
235 1.2.4.2 nathanw int offset;
236 1.2.4.2 nathanw int addr;
237 1.2.4.2 nathanw {
238 1.2.4.2 nathanw u_char *f = (u_char *)&addr;
239 1.2.4.2 nathanw u_int16_t v0, v1;
240 1.2.4.2 nathanw u_char *t;
241 1.2.4.2 nathanw
242 1.2.4.2 nathanw t = (u_char *)&v0;
243 1.2.4.2 nathanw t[0] = f[3]; t[1] = f[2];
244 1.2.4.2 nathanw bus_space_write_2(sc->bt, sc->bh, offset, v0);
245 1.2.4.2 nathanw
246 1.2.4.2 nathanw t = (u_char *)&v1;
247 1.2.4.2 nathanw t[0] = f[1]; t[1] = 0;
248 1.2.4.2 nathanw bus_space_write_2(sc->bt, sc->bh, offset+2, v1);
249 1.2.4.2 nathanw }
250 1.2.4.2 nathanw
251 1.2.4.2 nathanw int
252 1.2.4.2 nathanw ie_obio_match(parent, cf, aux)
253 1.2.4.2 nathanw struct device *parent;
254 1.2.4.2 nathanw struct cfdata *cf;
255 1.2.4.2 nathanw void *aux;
256 1.2.4.2 nathanw {
257 1.2.4.2 nathanw struct obio_attach_args *oba = aux;
258 1.2.4.2 nathanw bus_space_handle_t bh;
259 1.2.4.2 nathanw int matched;
260 1.2.4.2 nathanw u_int8_t ctrl;
261 1.2.4.2 nathanw
262 1.2.4.2 nathanw /* No default obio address. */
263 1.2.4.2 nathanw if (oba->oba_paddr == -1)
264 1.2.4.2 nathanw return(0);
265 1.2.4.2 nathanw
266 1.2.4.2 nathanw /* Make sure there is something there... */
267 1.2.4.2 nathanw if (bus_space_map(oba->oba_bustag, oba->oba_paddr, sizeof(struct ieob),
268 1.2.4.2 nathanw 0, &bh))
269 1.2.4.2 nathanw return (0);
270 1.2.4.2 nathanw matched = (!bus_space_poke_1(oba->oba_bustag, bh, 0, IEOB_NORSET) &&
271 1.2.4.2 nathanw !bus_space_peek_1(oba->oba_bustag, bh, 0, &ctrl) &&
272 1.2.4.2 nathanw (ctrl & (IEOB_ONAIR|IEOB_IENAB)) == 0);
273 1.2.4.2 nathanw bus_space_unmap(oba->oba_bustag, bh, sizeof(struct ieob));
274 1.2.4.2 nathanw if (!matched)
275 1.2.4.2 nathanw return (0);
276 1.2.4.2 nathanw
277 1.2.4.2 nathanw /* Default interrupt priority. */
278 1.2.4.2 nathanw if (oba->oba_pri == -1)
279 1.2.4.2 nathanw oba->oba_pri = 3;
280 1.2.4.2 nathanw
281 1.2.4.2 nathanw return (1);
282 1.2.4.2 nathanw }
283 1.2.4.2 nathanw
284 1.2.4.2 nathanw void
285 1.2.4.2 nathanw ie_obio_attach(parent, self, aux)
286 1.2.4.2 nathanw struct device *parent;
287 1.2.4.2 nathanw struct device *self;
288 1.2.4.2 nathanw void *aux;
289 1.2.4.2 nathanw {
290 1.2.4.2 nathanw struct obio_attach_args *oba = aux;
291 1.2.4.2 nathanw struct ie_softc *sc = (void *) self;
292 1.2.4.2 nathanw bus_dma_tag_t dmatag = oba->oba_dmatag;
293 1.2.4.2 nathanw bus_space_handle_t bh;
294 1.2.4.2 nathanw bus_dma_segment_t seg;
295 1.2.4.2 nathanw int rseg;
296 1.2.4.2 nathanw int error;
297 1.2.4.2 nathanw paddr_t pa;
298 1.2.4.2 nathanw struct intrhand *ih;
299 1.2.4.2 nathanw bus_size_t msize;
300 1.2.4.2 nathanw u_long iebase;
301 1.2.4.2 nathanw u_int8_t myaddr[ETHER_ADDR_LEN];
302 1.2.4.2 nathanw
303 1.2.4.2 nathanw sc->bt = oba->oba_bustag;
304 1.2.4.2 nathanw
305 1.2.4.2 nathanw sc->hwreset = ie_obreset;
306 1.2.4.2 nathanw sc->chan_attn = ie_obattend;
307 1.2.4.2 nathanw sc->hwinit = ie_obrun;
308 1.2.4.2 nathanw sc->memcopyout = ie_obio_memcopyout;
309 1.2.4.2 nathanw sc->memcopyin = ie_obio_memcopyin;
310 1.2.4.2 nathanw
311 1.2.4.2 nathanw sc->ie_bus_barrier = NULL;
312 1.2.4.2 nathanw sc->ie_bus_read16 = ie_obio_read16;
313 1.2.4.2 nathanw sc->ie_bus_write16 = ie_obio_write16;
314 1.2.4.2 nathanw sc->ie_bus_write24 = ie_obio_write24;
315 1.2.4.2 nathanw sc->sc_msize = msize = 65536; /* XXX */
316 1.2.4.2 nathanw
317 1.2.4.2 nathanw if (bus_space_map(oba->oba_bustag, oba->oba_paddr, sizeof(struct ieob),
318 1.2.4.2 nathanw 0, &bh))
319 1.2.4.2 nathanw panic("ie_obio_attach: can't map regs");
320 1.2.4.2 nathanw sc->sc_reg = (void *)bh;
321 1.2.4.2 nathanw
322 1.2.4.2 nathanw /*
323 1.2.4.2 nathanw * Allocate control & buffer memory.
324 1.2.4.2 nathanw */
325 1.2.4.2 nathanw if ((error = bus_dmamap_create(dmatag, msize, 1, msize, 0,
326 1.2.4.2 nathanw BUS_DMA_NOWAIT|BUS_DMA_24BIT,
327 1.2.4.2 nathanw &sc->sc_dmamap)) != 0) {
328 1.2.4.2 nathanw printf("%s: DMA map create error %d\n",
329 1.2.4.2 nathanw sc->sc_dev.dv_xname, error);
330 1.2.4.2 nathanw return;
331 1.2.4.2 nathanw }
332 1.2.4.2 nathanw if ((error = bus_dmamem_alloc(dmatag, msize, 64*1024, 0,
333 1.2.4.2 nathanw &seg, 1, &rseg,
334 1.2.4.2 nathanw BUS_DMA_NOWAIT | BUS_DMA_24BIT)) != 0) {
335 1.2.4.2 nathanw printf("%s: DMA memory allocation error %d\n",
336 1.2.4.2 nathanw self->dv_xname, error);
337 1.2.4.2 nathanw return;
338 1.2.4.2 nathanw }
339 1.2.4.2 nathanw
340 1.2.4.2 nathanw /* Map DMA buffer in CPU addressable space */
341 1.2.4.2 nathanw if ((error = bus_dmamem_map(dmatag, &seg, rseg, msize,
342 1.2.4.2 nathanw (caddr_t *)&sc->sc_maddr,
343 1.2.4.2 nathanw BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
344 1.2.4.2 nathanw printf("%s: DMA buffer map error %d\n",
345 1.2.4.2 nathanw sc->sc_dev.dv_xname, error);
346 1.2.4.2 nathanw bus_dmamem_free(dmatag, &seg, rseg);
347 1.2.4.2 nathanw return;
348 1.2.4.2 nathanw }
349 1.2.4.2 nathanw
350 1.2.4.2 nathanw /* Load the segment */
351 1.2.4.2 nathanw if ((error = bus_dmamap_load(dmatag, sc->sc_dmamap,
352 1.2.4.2 nathanw sc->sc_maddr, msize, NULL,
353 1.2.4.2 nathanw BUS_DMA_NOWAIT)) != 0) {
354 1.2.4.2 nathanw printf("%s: DMA buffer map load error %d\n",
355 1.2.4.2 nathanw sc->sc_dev.dv_xname, error);
356 1.2.4.2 nathanw bus_dmamem_unmap(dmatag, sc->sc_maddr, msize);
357 1.2.4.2 nathanw bus_dmamem_free(dmatag, &seg, rseg);
358 1.2.4.2 nathanw return;
359 1.2.4.2 nathanw }
360 1.2.4.2 nathanw
361 1.2.4.2 nathanw w16zero(sc->sc_maddr, msize);
362 1.2.4.2 nathanw sc->bh = (bus_space_handle_t)(sc->sc_maddr);
363 1.2.4.2 nathanw
364 1.2.4.2 nathanw /*
365 1.2.4.2 nathanw * The i82586's 24-bit address space maps to all of
366 1.2.4.2 nathanw * KVA space (). In addition, the SCP must appear
367 1.2.4.2 nathanw * at IE_SCP_ADDR within the 24-bit address space,
368 1.2.4.2 nathanw * i.e. at KVA IEOB_ADBASE+IE_SCP_ADDR, at the very top of
369 1.2.4.2 nathanw * kernel space. We double-map this last page to the first
370 1.2.4.2 nathanw * page (starting at `maddr') of the memory we allocate to the chip.
371 1.2.4.2 nathanw * (a side-effect of this double-map is that the ISCP and SCB
372 1.2.4.2 nathanw * structures also get aliased there, but we ignore this). The
373 1.2.4.2 nathanw * first page at `maddr' is only used for ISCP, SCB and the aliased
374 1.2.4.2 nathanw * SCP; the actual buffers start at maddr+NBPG.
375 1.2.4.2 nathanw *
376 1.2.4.2 nathanw * In a picture:
377 1.2.4.2 nathanw
378 1.2.4.2 nathanw |---//--- ISCP-SCB-----scp-|--//- buffers -//-|... |iscp-scb-----SCP-|
379 1.2.4.2 nathanw | | | | | | |
380 1.2.4.2 nathanw | |<----- NBPG --->| | |<----- NBPG -+-->|
381 1.2.4.2 nathanw | |<------------- msize ------------->| | ^ |
382 1.2.4.2 nathanw | | | |
383 1.2.4.2 nathanw | \@maddr (last page dbl mapped)
384 1.2.4.2 nathanw | |
385 1.2.4.2 nathanw \@IEOB_ADBASE @IEOB_ADBASE+IE_SCP_ADDR-+
386 1.2.4.2 nathanw
387 1.2.4.2 nathanw *
388 1.2.4.2 nathanw */
389 1.2.4.2 nathanw
390 1.2.4.2 nathanw /* Double map the SCP */
391 1.2.4.2 nathanw if (pmap_extract(pmap_kernel(), (vaddr_t)sc->sc_maddr, &pa) == FALSE)
392 1.2.4.2 nathanw panic("ie pmap_extract");
393 1.2.4.2 nathanw
394 1.2.4.2 nathanw pmap_enter(pmap_kernel(), m68k_trunc_page(IEOB_ADBASE+IE_SCP_ADDR),
395 1.2.4.2 nathanw pa | PMAP_NC /*| PMAP_IOC*/,
396 1.2.4.2 nathanw VM_PROT_READ | VM_PROT_WRITE, PMAP_WIRED);
397 1.2.4.2 nathanw
398 1.2.4.2 nathanw /* Map iscp at location 0 (relative to `maddr') */
399 1.2.4.2 nathanw sc->iscp = 0;
400 1.2.4.2 nathanw
401 1.2.4.2 nathanw /* scb follows iscp */
402 1.2.4.2 nathanw sc->scb = IE_ISCP_SZ;
403 1.2.4.2 nathanw
404 1.2.4.2 nathanw /* scp is at the fixed location IE_SCP_ADDR (modulo the page size) */
405 1.2.4.2 nathanw sc->scp = IE_SCP_ADDR & PGOFSET;
406 1.2.4.2 nathanw
407 1.2.4.2 nathanw /* Calculate the 24-bit base of i82586 operations */
408 1.2.4.2 nathanw iebase = (u_long)sc->sc_dmamap->dm_segs[0].ds_addr -
409 1.2.4.2 nathanw (u_long)IEOB_ADBASE;
410 1.2.4.2 nathanw ie_obio_write16(sc, IE_ISCP_SCB(sc->iscp), sc->scb);
411 1.2.4.2 nathanw ie_obio_write24(sc, IE_ISCP_BASE(sc->iscp), iebase);
412 1.2.4.2 nathanw ie_obio_write24(sc, IE_SCP_ISCP(sc->scp), iebase + sc->iscp);
413 1.2.4.2 nathanw
414 1.2.4.2 nathanw /*
415 1.2.4.2 nathanw * Rest of first page is unused (wasted!); the other pages
416 1.2.4.2 nathanw * are used for buffers.
417 1.2.4.2 nathanw */
418 1.2.4.2 nathanw sc->buf_area = NBPG;
419 1.2.4.2 nathanw sc->buf_area_sz = msize - NBPG;
420 1.2.4.2 nathanw
421 1.2.4.2 nathanw if (i82586_proberam(sc) == 0) {
422 1.2.4.2 nathanw printf(": memory probe failed\n");
423 1.2.4.2 nathanw return;
424 1.2.4.2 nathanw }
425 1.2.4.2 nathanw
426 1.2.4.2 nathanw idprom_etheraddr(myaddr);
427 1.2.4.2 nathanw i82586_attach(sc, "onboard", myaddr, media, NMEDIA, media[0]);
428 1.2.4.2 nathanw
429 1.2.4.2 nathanw /* Establish interrupt channel */
430 1.2.4.2 nathanw ih = bus_intr_establish(oba->oba_bustag,
431 1.2.4.2 nathanw oba->oba_pri, IPL_NET, 0,
432 1.2.4.2 nathanw i82586_intr, sc);
433 1.2.4.2 nathanw }
434