if_ef.c revision 1.1 1 1.1 pk /* $NetBSD: if_ef.c,v 1.1 1998/02/27 23:51:52 pk Exp $ */
2 1.1 pk /* $Id: if_ef.c,v 1.1 1998/02/27 23:51:52 pk Exp $ */
3 1.1 pk
4 1.1 pk /*-
5 1.1 pk * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 1.1 pk * All rights reserved.
7 1.1 pk *
8 1.1 pk * This code is derived from software contributed to The NetBSD Foundation
9 1.1 pk * by Rafal K. Boni.
10 1.1 pk *
11 1.1 pk * Redistribution and use in source and binary forms, with or without
12 1.1 pk * modification, are permitted provided that the following conditions
13 1.1 pk * are met:
14 1.1 pk * 1. Redistributions of source code must retain the above copyright
15 1.1 pk * notice, this list of conditions and the following disclaimer.
16 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 pk * notice, this list of conditions and the following disclaimer in the
18 1.1 pk * documentation and/or other materials provided with the distribution.
19 1.1 pk * 3. All advertising materials mentioning features or use of this software
20 1.1 pk * must display the following acknowledgement:
21 1.1 pk * This product includes software developed by the NetBSD
22 1.1 pk * Foundation, Inc. and its contributors.
23 1.1 pk * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1 pk * contributors may be used to endorse or promote products derived
25 1.1 pk * from this software without specific prior written permission.
26 1.1 pk *
27 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1 pk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1 pk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1 pk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1 pk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1 pk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1 pk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1 pk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1 pk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1 pk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1 pk * POSSIBILITY OF SUCH DAMAGE.
38 1.1 pk */
39 1.1 pk
40 1.1 pk #include <sys/param.h>
41 1.1 pk #include <sys/systm.h>
42 1.1 pk #include <sys/mbuf.h>
43 1.1 pk #include <sys/errno.h>
44 1.1 pk #include <sys/device.h>
45 1.1 pk #include <sys/protosw.h>
46 1.1 pk #include <sys/socket.h>
47 1.1 pk
48 1.1 pk #include <net/if.h>
49 1.1 pk #include <net/if_dl.h>
50 1.1 pk #include <net/if_types.h>
51 1.1 pk #include <net/if_media.h>
52 1.1 pk #include <net/if_ether.h>
53 1.1 pk
54 1.1 pk #include <vm/vm.h>
55 1.1 pk
56 1.1 pk #include <machine/cpu.h>
57 1.1 pk #include <machine/bus.h>
58 1.1 pk #include <machine/intr.h>
59 1.1 pk
60 1.1 pk #include <dev/isa/isareg.h>
61 1.1 pk #include <dev/isa/isavar.h>
62 1.1 pk
63 1.1 pk #define _NEW_I82586
64 1.1 pk #include <dev/ic/i82586reg.h>
65 1.1 pk #include <dev/ic/i82586var.h>
66 1.1 pk #include <dev/isa/if_efreg.h>
67 1.1 pk #include <dev/isa/elink.h>
68 1.1 pk
69 1.1 pk #ifdef EF_DEBUG
70 1.1 pk #define DPRINTF(x) printf x
71 1.1 pk #else
72 1.1 pk #define DPRINTF(x)
73 1.1 pk #endif
74 1.1 pk
75 1.1 pk struct ef_softc {
76 1.1 pk struct ie_softc sc_ie;
77 1.1 pk
78 1.1 pk bus_space_tag_t sc_regt; /* space tag for registers */
79 1.1 pk bus_space_handle_t sc_regh; /* space handle for registers */
80 1.1 pk
81 1.1 pk void* sc_ih; /* interrupt handle */
82 1.1 pk
83 1.1 pk u_int8_t card_rev; /* hardware revision */
84 1.1 pk u_int8_t card_type; /* card model -- AUI/BNC or TP */
85 1.1 pk };
86 1.1 pk
87 1.1 pk int ef_media[] = {
88 1.1 pk IFM_ETHER | IFM_10_5,
89 1.1 pk IFM_ETHER | IFM_10_2,
90 1.1 pk };
91 1.1 pk #define NEF_MEDIA (sizeof(ef_media) / sizeof(ef_media[0]))
92 1.1 pk
93 1.1 pk int eftp_media[] = {
94 1.1 pk IFM_ETHER | IFM_10_T,
95 1.1 pk };
96 1.1 pk #define NEFTP_MEDIA (sizeof(eftp_media) / sizeof(eftp_media[0]))
97 1.1 pk
98 1.1 pk /* Routines required by the MI i82586 driver API */
99 1.1 pk static void ef_reset __P((struct ie_softc *, int));
100 1.1 pk static void ef_hwinit __P((struct ie_softc *));
101 1.1 pk static void ef_atten __P((struct ie_softc *));
102 1.1 pk static int ef_intrhook __P((struct ie_softc *, int));
103 1.1 pk
104 1.1 pk static void ef_copyin __P((struct ie_softc *, void *, int, size_t));
105 1.1 pk static void ef_copyout __P((struct ie_softc *, const void *, int, size_t));
106 1.1 pk
107 1.1 pk static u_int16_t ef_read_16 __P((struct ie_softc *, int));
108 1.1 pk static void ef_write_16 __P((struct ie_softc *, int, u_int16_t));
109 1.1 pk static void ef_write_24 __P((struct ie_softc *, int, int));
110 1.1 pk
111 1.1 pk static void ef_mediastatus __P((struct ie_softc *, struct ifmediareq *));
112 1.1 pk
113 1.1 pk /* Local routines */
114 1.1 pk static int ef_port_check __P((bus_space_tag_t, bus_space_handle_t));
115 1.1 pk
116 1.1 pk #ifdef __BROKEN_INDIRECT_CONFIG
117 1.1 pk int ef_match __P((struct device *, void*, void *));
118 1.1 pk #else
119 1.1 pk int ef_match __P((struct device *, struct cfdata *, void *));
120 1.1 pk #endif
121 1.1 pk void ef_attach __P((struct device *, struct device *, void *));
122 1.1 pk
123 1.1 pk /*
124 1.1 pk * This keeps track of which ISAs have been through an ie probe sequence.
125 1.1 pk * A simple static variable isn't enough, since it's conceivable that
126 1.1 pk * a system might have more than one ISA bus.
127 1.1 pk *
128 1.1 pk * The "isa_bus" member is a pointer to the parent ISA bus device struct
129 1.1 pk * which will unique per ISA bus.
130 1.1 pk */
131 1.1 pk
132 1.1 pk #define MAXCARDS_PER_ISABUS 8 /* if you have more than 8, you lose */
133 1.1 pk
134 1.1 pk struct ef_isabus {
135 1.1 pk LIST_ENTRY(ef_isabus) isa_link;
136 1.1 pk struct device *isa_bus;
137 1.1 pk
138 1.1 pk int bus_state;
139 1.1 pk
140 1.1 pk struct card {
141 1.1 pk bus_addr_t iobase;
142 1.1 pk bus_addr_t maddr;
143 1.1 pk bus_size_t msize;
144 1.1 pk int irq;
145 1.1 pk int available;
146 1.1 pk } isa_cards[MAXCARDS_PER_ISABUS];
147 1.1 pk };
148 1.1 pk
149 1.1 pk static LIST_HEAD(, ef_isabus) ef_isa_buses;
150 1.1 pk static int ef_isa_buses_inited;
151 1.1 pk
152 1.1 pk static void
153 1.1 pk ef_card_add(
154 1.1 pk struct ef_isabus *bus,
155 1.1 pk bus_addr_t iobase,
156 1.1 pk bus_addr_t maddr,
157 1.1 pk bus_size_t msize,
158 1.1 pk int irq)
159 1.1 pk {
160 1.1 pk int idx;
161 1.1 pk
162 1.1 pk DPRINTF(("Adding 3c507 at 0x%x, IRQ %d, Mem 0x%lx/%ld\n", (u_int) iobase,
163 1.1 pk irq, (u_long) maddr, msize));
164 1.1 pk
165 1.1 pk for (idx = 0; idx < MAXCARDS_PER_ISABUS; idx++) {
166 1.1 pk if (bus->isa_cards[idx].available == 0) {
167 1.1 pk bus->isa_cards[idx].iobase = iobase;
168 1.1 pk bus->isa_cards[idx].maddr = maddr;
169 1.1 pk bus->isa_cards[idx].msize = msize;
170 1.1 pk bus->isa_cards[idx].irq = irq;
171 1.1 pk bus->isa_cards[idx].available = 1;
172 1.1 pk break;
173 1.1 pk }
174 1.1 pk }
175 1.1 pk }
176 1.1 pk
177 1.1 pk /*
178 1.1 pk * 3C507 support routines
179 1.1 pk */
180 1.1 pk static void
181 1.1 pk ef_reset(sc, why)
182 1.1 pk struct ie_softc *sc;
183 1.1 pk int why;
184 1.1 pk {
185 1.1 pk struct ef_softc* esc = (struct ef_softc *) sc;
186 1.1 pk
187 1.1 pk switch (why) {
188 1.1 pk
189 1.1 pk case CHIP_PROBE: /* reset to chip to see if it responds */
190 1.1 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_CTRL, EF_CTRL_RESET);
191 1.1 pk DELAY(100);
192 1.1 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_CTRL, EF_CTRL_NORMAL);
193 1.1 pk DELAY(100);
194 1.1 pk break;
195 1.1 pk
196 1.1 pk case CARD_RESET: /* this takes around 10sec, and we can get
197 1.1 pk break; * by quite well w/out it... */
198 1.1 pk }
199 1.1 pk }
200 1.1 pk
201 1.1 pk static void
202 1.1 pk ef_atten(sc)
203 1.1 pk struct ie_softc *sc;
204 1.1 pk {
205 1.1 pk struct ef_softc* esc = (struct ef_softc *) sc;
206 1.1 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ATTN, 1);
207 1.1 pk }
208 1.1 pk
209 1.1 pk static void
210 1.1 pk ef_hwinit(sc)
211 1.1 pk struct ie_softc *sc;
212 1.1 pk {
213 1.1 pk struct ef_softc* esc = (struct ef_softc *) sc;
214 1.1 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1);
215 1.1 pk }
216 1.1 pk
217 1.1 pk static int
218 1.1 pk ef_intrhook(sc, where)
219 1.1 pk struct ie_softc *sc;
220 1.1 pk int where;
221 1.1 pk {
222 1.1 pk unsigned char cr;
223 1.1 pk struct ef_softc* esc = (struct ef_softc *) sc;
224 1.1 pk
225 1.1 pk switch (where) {
226 1.1 pk
227 1.1 pk case INTR_ENTER: /* entering ISR: disable, ack card interrupts */
228 1.1 pk cr = bus_space_read_1(esc->sc_regt, esc->sc_regh, EF_CTRL);
229 1.1 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_CTRL,
230 1.1 pk cr & ~EF_CTRL_IEN);
231 1.1 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1);
232 1.1 pk break;
233 1.1 pk
234 1.1 pk case INTR_EXIT: /* exiting ISR: re-enable card interrupts */
235 1.1 pk cr = bus_space_read_1(esc->sc_regt, esc->sc_regh, EF_CTRL);
236 1.1 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_CTRL,
237 1.1 pk cr | EF_CTRL_IEN);
238 1.1 pk break;
239 1.1 pk
240 1.1 pk case INTR_LOOP: /* looping in ISR: ack new interrupts */
241 1.1 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1);
242 1.1 pk break;
243 1.1 pk }
244 1.1 pk
245 1.1 pk return 1;
246 1.1 pk }
247 1.1 pk
248 1.1 pk static u_int16_t
249 1.1 pk ef_read_16 (sc, offset)
250 1.1 pk struct ie_softc *sc;
251 1.1 pk int offset;
252 1.1 pk {
253 1.1 pk bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_READ);
254 1.1 pk return bus_space_read_2(sc->bt, sc->bh, offset);
255 1.1 pk }
256 1.1 pk
257 1.1 pk static void
258 1.1 pk ef_copyin (sc, dst, offset, size)
259 1.1 pk struct ie_softc *sc;
260 1.1 pk void *dst;
261 1.1 pk int offset;
262 1.1 pk size_t size;
263 1.1 pk {
264 1.1 pk int dribble;
265 1.1 pk u_int8_t* bptr = dst;
266 1.1 pk
267 1.1 pk bus_space_barrier(sc->bt, sc->bh, offset, size, BUS_SPACE_BARRIER_READ);
268 1.1 pk
269 1.1 pk if (offset % 2) {
270 1.1 pk *bptr = bus_space_read_1(sc->bt, sc->bh, offset);
271 1.1 pk offset++; bptr++; size--;
272 1.1 pk }
273 1.1 pk
274 1.1 pk dribble = size % 2;
275 1.1 pk bus_space_read_region_2(sc->bt, sc->bh, offset, (u_int16_t *) bptr,
276 1.1 pk size >> 1);
277 1.1 pk
278 1.1 pk if (dribble) {
279 1.1 pk bptr += size - 1;
280 1.1 pk offset += size - 1;
281 1.1 pk *bptr = bus_space_read_1(sc->bt, sc->bh, offset);
282 1.1 pk }
283 1.1 pk }
284 1.1 pk
285 1.1 pk static void
286 1.1 pk ef_copyout (sc, src, offset, size)
287 1.1 pk struct ie_softc *sc;
288 1.1 pk const void *src;
289 1.1 pk int offset;
290 1.1 pk size_t size;
291 1.1 pk {
292 1.1 pk int dribble;
293 1.1 pk int osize = size;
294 1.1 pk int ooffset = offset;
295 1.1 pk const u_int8_t* bptr = src;
296 1.1 pk
297 1.1 pk if (offset % 2) {
298 1.1 pk bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
299 1.1 pk offset++; bptr++; size--;
300 1.1 pk }
301 1.1 pk
302 1.1 pk dribble = size % 2;
303 1.1 pk bus_space_write_region_2(sc->bt, sc->bh, offset, (u_int16_t *)bptr,
304 1.1 pk size >> 1);
305 1.1 pk if (dribble) {
306 1.1 pk bptr += size - 1;
307 1.1 pk offset += size - 1;
308 1.1 pk bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
309 1.1 pk }
310 1.1 pk
311 1.1 pk bus_space_barrier(sc->bt, sc->bh, ooffset, osize, BUS_SPACE_BARRIER_WRITE);
312 1.1 pk }
313 1.1 pk
314 1.1 pk static void
315 1.1 pk ef_write_16 (sc, offset, value)
316 1.1 pk struct ie_softc *sc;
317 1.1 pk int offset;
318 1.1 pk u_int16_t value;
319 1.1 pk {
320 1.1 pk bus_space_write_2(sc->bt, sc->bh, offset, value);
321 1.1 pk bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_WRITE);
322 1.1 pk }
323 1.1 pk
324 1.1 pk static void
325 1.1 pk ef_write_24 (sc, offset, addr)
326 1.1 pk struct ie_softc *sc;
327 1.1 pk int offset, addr;
328 1.1 pk {
329 1.1 pk bus_space_write_4(sc->bt, sc->bh, offset, addr +
330 1.1 pk (u_long) sc->sc_maddr - (u_long) sc->sc_iobase);
331 1.1 pk bus_space_barrier(sc->bt, sc->bh, offset, 4, BUS_SPACE_BARRIER_WRITE);
332 1.1 pk }
333 1.1 pk
334 1.1 pk static void
335 1.1 pk ef_mediastatus(sc, ifmr)
336 1.1 pk struct ie_softc *sc;
337 1.1 pk struct ifmediareq *ifmr;
338 1.1 pk {
339 1.1 pk struct ifmedia *ifm = &sc->sc_media;
340 1.1 pk
341 1.1 pk /*
342 1.1 pk * The currently selected media is always the active media.
343 1.1 pk */
344 1.1 pk ifmr->ifm_active = ifm->ifm_cur->ifm_media;
345 1.1 pk }
346 1.1 pk
347 1.1 pk int
348 1.1 pk ef_match(parent, cf, aux)
349 1.1 pk struct device *parent;
350 1.1 pk #ifdef __BROKEN_INDIRECT_CONFIG
351 1.1 pk void *cf;
352 1.1 pk #else
353 1.1 pk struct cfdata *cf;
354 1.1 pk #endif
355 1.1 pk void *aux;
356 1.1 pk {
357 1.1 pk struct ef_softc *sc = (struct ef_softc *) cf;
358 1.1 pk struct isa_attach_args * const ia = aux;
359 1.1 pk
360 1.1 pk int idx;
361 1.1 pk struct ef_isabus *bus;
362 1.1 pk
363 1.1 pk bus_space_handle_t ioh;
364 1.1 pk bus_space_tag_t iot = ia->ia_iot;
365 1.1 pk
366 1.1 pk if (ef_isa_buses_inited == 0) {
367 1.1 pk LIST_INIT(&ef_isa_buses);
368 1.1 pk ef_isa_buses_inited = 1;
369 1.1 pk }
370 1.1 pk
371 1.1 pk /*
372 1.1 pk * Probe this bus if we haven't done so already.
373 1.1 pk */
374 1.1 pk for (bus = ef_isa_buses.lh_first; bus != NULL;
375 1.1 pk bus = bus->isa_link.le_next) {
376 1.1 pk if (bus->isa_bus == parent)
377 1.1 pk break;
378 1.1 pk }
379 1.1 pk
380 1.1 pk if (bus == NULL) {
381 1.1 pk bus_addr_t iobase;
382 1.1 pk
383 1.1 pk /*
384 1.1 pk * Mark this bus so we don't probe it again.
385 1.1 pk */
386 1.1 pk bus = (struct ef_isabus *)
387 1.1 pk malloc(sizeof(struct ef_isabus), M_DEVBUF, M_NOWAIT);
388 1.1 pk if (bus == NULL)
389 1.1 pk panic("ef_isa_probe: can't allocate state storage for %s",
390 1.1 pk parent->dv_xname);
391 1.1 pk
392 1.1 pk bus->bus_state = 0; /* nothing done yet */
393 1.1 pk bus->isa_bus = parent;
394 1.1 pk
395 1.1 pk LIST_INSERT_HEAD(&ef_isa_buses, bus, isa_link);
396 1.1 pk
397 1.1 pk if (bus_space_map(iot, ELINK_ID_PORT, 1, 0, &ioh)) {
398 1.1 pk DPRINTF(("3c507 probe: can't map Etherlink ID port\n"));
399 1.1 pk return 0;
400 1.1 pk }
401 1.1 pk
402 1.1 pk /*
403 1.1 pk * Reset and put card in CONFIG state without changing address.
404 1.1 pk */
405 1.1 pk elink_reset(iot, ioh, sc->sc_ie.sc_dev.dv_parent->dv_unit);
406 1.1 pk elink_idseq(iot, ioh, ELINK_507_POLY);
407 1.1 pk elink_idseq(iot, ioh, ELINK_507_POLY);
408 1.1 pk bus_space_write_1(iot, ioh, 0, 0xff);
409 1.1 pk
410 1.1 pk /* Unmap the ID port */
411 1.1 pk bus_space_unmap(iot, ioh, 1);
412 1.1 pk
413 1.1 pk bus->bus_state++; /* cards now in CONFIG state */
414 1.1 pk
415 1.1 pk for (iobase = EF_IOBASE_LOW; iobase <= EF_IOBASE_HIGH;
416 1.1 pk iobase += EF_IOSIZE) {
417 1.1 pk /*
418 1.1 pk * Map the 507's port-space for the probe sequence.
419 1.1 pk */
420 1.1 pk if (bus_space_map(iot, iobase, EF_IOSIZE, 0, &ioh) != 0)
421 1.1 pk continue;
422 1.1 pk
423 1.1 pk /* Now look for the 3Com magic bytes */
424 1.1 pk
425 1.1 pk if (ef_port_check(iot, ioh)) {
426 1.1 pk int irq;
427 1.1 pk u_int8_t v;
428 1.1 pk bus_addr_t maddr;
429 1.1 pk bus_addr_t msize;
430 1.1 pk bus_space_handle_t memh;
431 1.1 pk
432 1.1 pk irq = bus_space_read_1(iot, ioh, EF_IRQ) & EF_IRQ_MASK;
433 1.1 pk
434 1.1 pk v = bus_space_read_1(iot, ioh, EF_MADDR);
435 1.1 pk maddr = ((v & EF_MADDR_MASK) << EF_MADDR_SHIFT) + EF_MADDR_BASE;
436 1.1 pk msize = ((v & EF_MSIZE_MASK) + 1) * EF_MSIZE_STEP;
437 1.1 pk
438 1.1 pk if (bus_space_map(ia->ia_memt, maddr, msize, 0, &memh) == 0) {
439 1.1 pk ef_card_add(bus, iobase, maddr, msize, irq);
440 1.1 pk bus_space_unmap(ia->ia_memt, memh, msize);
441 1.1 pk }
442 1.1 pk }
443 1.1 pk bus_space_unmap(iot, ioh, EF_IOSIZE);
444 1.1 pk }
445 1.1 pk }
446 1.1 pk
447 1.1 pk for (idx = 0; idx < MAXCARDS_PER_ISABUS; idx++) {
448 1.1 pk if (bus->isa_cards[idx].available != 1)
449 1.1 pk continue;
450 1.1 pk if (ia->ia_iobase != IOBASEUNK
451 1.1 pk && ia->ia_iobase != bus->isa_cards[idx].iobase)
452 1.1 pk continue;
453 1.1 pk if (ia->ia_maddr != MADDRUNK
454 1.1 pk && ia->ia_maddr != bus->isa_cards[idx].maddr)
455 1.1 pk continue;
456 1.1 pk if (ia->ia_irq != IRQUNK && ia->ia_irq != bus->isa_cards[idx].irq)
457 1.1 pk continue;
458 1.1 pk break;
459 1.1 pk }
460 1.1 pk if (idx == MAXCARDS_PER_ISABUS)
461 1.1 pk return 0;
462 1.1 pk
463 1.1 pk bus->isa_cards[idx].available++;
464 1.1 pk ia->ia_iobase = bus->isa_cards[idx].iobase;
465 1.1 pk ia->ia_irq = bus->isa_cards[idx].irq;
466 1.1 pk ia->ia_iosize = EF_IOSIZE;
467 1.1 pk ia->ia_maddr = bus->isa_cards[idx].maddr;
468 1.1 pk ia->ia_msize = bus->isa_cards[idx].msize;
469 1.1 pk return 1;
470 1.1 pk }
471 1.1 pk
472 1.1 pk void
473 1.1 pk ef_attach(parent, self, aux)
474 1.1 pk struct device *parent;
475 1.1 pk struct device *self;
476 1.1 pk void *aux;
477 1.1 pk {
478 1.1 pk struct ef_softc *esc = (void *)self;
479 1.1 pk struct ie_softc *sc = &esc->sc_ie;
480 1.1 pk struct isa_attach_args *ia = aux;
481 1.1 pk bus_space_tag_t iot = ia->ia_iot;
482 1.1 pk
483 1.1 pk int i;
484 1.1 pk char version[20];
485 1.1 pk struct ef_isabus *bus;
486 1.1 pk u_int8_t partno[EF_TYPE_LEN];
487 1.1 pk bus_space_handle_t ioh, memh;
488 1.1 pk u_int8_t ethaddr[ETHER_ADDR_LEN];
489 1.1 pk
490 1.1 pk sc->hwinit = ef_hwinit;
491 1.1 pk sc->hwreset = ef_reset;
492 1.1 pk sc->chan_attn = ef_atten;
493 1.1 pk sc->intrhook = ef_intrhook;
494 1.1 pk
495 1.1 pk sc->memcopyin = ef_copyin;
496 1.1 pk sc->memcopyout = ef_copyout;
497 1.1 pk sc->ie_bus_read16 = ef_read_16;
498 1.1 pk sc->ie_bus_write16 = ef_write_16;
499 1.1 pk sc->ie_bus_write24 = ef_write_24;
500 1.1 pk
501 1.1 pk sc->sc_msize = 0;
502 1.1 pk
503 1.1 pk /*
504 1.1 pk * NOP chains don't give any advantage on this card, in fact they seem
505 1.1 pk * to slow it down some. As the doctor says, "if it hurts, don't do it".
506 1.1 pk */
507 1.1 pk sc->do_xmitnopchain = 0;
508 1.1 pk
509 1.1 pk sc->sc_mediachange = NULL;
510 1.1 pk sc->sc_mediastatus = ef_mediastatus;
511 1.1 pk
512 1.1 pk /* Find the cards parent bus */
513 1.1 pk for (bus = ef_isa_buses.lh_first; bus != NULL;
514 1.1 pk bus = bus->isa_link.le_next) {
515 1.1 pk if (bus->isa_bus == parent)
516 1.1 pk break;
517 1.1 pk }
518 1.1 pk
519 1.1 pk if (bus == NULL)
520 1.1 pk panic("%s: Can't find parent bus!", sc->sc_dev.dv_xname);
521 1.1 pk
522 1.1 pk
523 1.1 pk /* If the bus hasn't been transitioned to the RUN state, do so now */
524 1.1 pk if (bus->bus_state == 1) {
525 1.1 pk if (bus_space_map(iot, ELINK_ID_PORT, 1, 0, &ioh) != 0) {
526 1.1 pk DPRINTF(("\n%s: Can't map Elink ID port!\n", sc->sc_dev.dv_xname));
527 1.1 pk return;
528 1.1 pk }
529 1.1 pk
530 1.1 pk bus_space_write_1(ia->ia_iot, ioh, 0, 0x00);
531 1.1 pk elink_idseq(ia->ia_iot, ioh, ELINK_507_POLY);
532 1.1 pk bus_space_write_1(ia->ia_iot, ioh, 0, 0x00);
533 1.1 pk bus_space_unmap(ia->ia_iot, ioh, 1);
534 1.1 pk
535 1.1 pk bus->bus_state++;
536 1.1 pk }
537 1.1 pk
538 1.1 pk /* Map i/o space. */
539 1.1 pk if (bus_space_map(ia->ia_iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh) != 0) {
540 1.1 pk DPRINTF(("\n%s: can't map i/o space 0x%x-0x%x\n",
541 1.1 pk sc->sc_dev.dv_xname, ia->ia_iobase,
542 1.1 pk ia->ia_iobase + ia->ia_iosize - 1));
543 1.1 pk return;
544 1.1 pk }
545 1.1 pk
546 1.1 pk esc->sc_regt = ia->ia_iot;
547 1.1 pk esc->sc_regh = ioh;
548 1.1 pk
549 1.1 pk if (bus_space_map(ia->ia_memt, ia->ia_maddr, ia->ia_msize, 0, &memh) != 0) {
550 1.1 pk DPRINTF(("\n%s: can't map iomem space 0x%x-0x%x\n",
551 1.1 pk sc->sc_dev.dv_xname, ia->ia_maddr,
552 1.1 pk ia->ia_maddr + ia->ia_msize - 1));
553 1.1 pk bus_space_unmap(ia->ia_iot, ioh, ia->ia_iosize);
554 1.1 pk return;
555 1.1 pk }
556 1.1 pk
557 1.1 pk sc->bt = ia->ia_memt;
558 1.1 pk sc->bh = memh;
559 1.1 pk
560 1.1 pk sc->sc_msize = ia->ia_msize;
561 1.1 pk sc->sc_maddr = (void *) memh;
562 1.1 pk sc->sc_iobase = sc->sc_maddr + sc->sc_msize - (1 << 24);
563 1.1 pk
564 1.1 pk /* set up pointers to important on-card control structures */
565 1.1 pk sc->iscp = 0;
566 1.1 pk sc->scb = IE_ISCP_SZ;
567 1.1 pk sc->scp = sc->sc_msize + IE_SCP_ADDR - (1 << 24);
568 1.1 pk
569 1.1 pk sc->buf_area = sc->scb + IE_SCB_SZ;
570 1.1 pk sc->buf_area_sz = sc->sc_msize - IE_ISCP_SZ - IE_SCB_SZ - IE_SCP_SZ;
571 1.1 pk
572 1.1 pk /* zero card memory */
573 1.1 pk bus_space_set_region_1(sc->bt, sc->bh, 0, 0, sc->sc_msize);
574 1.1 pk
575 1.1 pk /* set card to 16-bit bus mode */
576 1.1 pk bus_space_write_1(sc->bt, sc->bh, IE_SCP_BUS_USE((u_long) sc->scp), 0);
577 1.1 pk
578 1.1 pk /* set up pointers to key structures */
579 1.1 pk ef_write_24(sc, IE_SCP_ISCP((u_long)sc->scp), (u_long) sc->iscp);
580 1.1 pk ef_write_16(sc, IE_ISCP_SCB((u_long)sc->iscp), (u_long) sc->scb);
581 1.1 pk ef_write_24(sc, IE_ISCP_BASE((u_long)sc->iscp), (u_long) sc->iscp);
582 1.1 pk
583 1.1 pk /* flush setup of pointers, check if chip answers */
584 1.1 pk bus_space_barrier(sc->bt, sc->bh, 0, sc->sc_msize, BUS_SPACE_BARRIER_WRITE);
585 1.1 pk if (!i82586_proberam(sc)) {
586 1.1 pk DPRINTF(("\n%s: can't talk to i82586!\n", sc->sc_dev.dv_xname));
587 1.1 pk bus_space_unmap(ia->ia_iot, ioh, ia->ia_iosize);
588 1.1 pk bus_space_unmap(ia->ia_memt, memh, ia->ia_msize);
589 1.1 pk return;
590 1.1 pk }
591 1.1 pk
592 1.1 pk /* set bank 2 for card part number and revision */
593 1.1 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_CTRL, EF_CTRL_NRST |
594 1.1 pk EF_CTRL_BNK2);
595 1.1 pk
596 1.1 pk /* card revision is encoded in BCD */
597 1.1 pk i = bus_space_read_1(esc->sc_regt, esc->sc_regh, EF_REV);
598 1.1 pk esc->card_rev = 10*(i / 16) + (i % 16);
599 1.1 pk
600 1.1 pk for (i = 0; i < EF_TYPE_LEN; i++)
601 1.1 pk partno[i] = bus_space_read_1(esc->sc_regt, esc->sc_regh, EF_TYPE + i);
602 1.1 pk
603 1.1 pk /* use part number to guess if card is TP or AUI/BNC model */
604 1.1 pk esc->card_type = EF_IS_TP(partno) ? EF_CARD_TP : EF_CARD_BNC;
605 1.1 pk
606 1.1 pk /* set bank 0 for ethernet address */
607 1.1 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_CTRL, EF_CTRL_NORMAL);
608 1.1 pk for (i = 0; i < EF_ADDR_LEN; i++)
609 1.1 pk ethaddr[i] = bus_space_read_1(esc->sc_regt, esc->sc_regh, EF_ADDR + i);
610 1.1 pk
611 1.1 pk sprintf(version, "%s, rev. %d",
612 1.1 pk (esc->card_type == EF_CARD_TP) ? "3C507-TP" : "3C507", esc->card_rev);
613 1.1 pk
614 1.1 pk if (esc->card_type == EF_CARD_TP)
615 1.1 pk i82586_attach(sc, version, ethaddr, eftp_media, NEFTP_MEDIA,
616 1.1 pk eftp_media[0]);
617 1.1 pk else {
618 1.1 pk u_int8_t media = bus_space_read_1(esc->sc_regt, esc->sc_regh, EF_MEDIA);
619 1.1 pk media = (media & EF_MEDIA_MASK) >> EF_MEDIA_SHIFT;
620 1.1 pk
621 1.1 pk i82586_attach(sc, version, ethaddr, ef_media, NEF_MEDIA,
622 1.1 pk ef_media[media]);
623 1.1 pk }
624 1.1 pk
625 1.1 pk /* Clear the interrupt latch just in case. */
626 1.1 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1);
627 1.1 pk
628 1.1 pk esc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
629 1.1 pk IPL_NET, i82586_intr, sc);
630 1.1 pk if (esc->sc_ih == NULL) {
631 1.1 pk DPRINTF(("\n%s: can't establish interrupt\n", sc->sc_dev.dv_xname));
632 1.1 pk }
633 1.1 pk }
634 1.1 pk
635 1.1 pk static int
636 1.1 pk ef_port_check(iot, ioh)
637 1.1 pk bus_space_tag_t iot;
638 1.1 pk bus_space_handle_t ioh;
639 1.1 pk {
640 1.1 pk int i;
641 1.1 pk u_char ch;
642 1.1 pk u_char* signature = EF_SIGNATURE;
643 1.1 pk
644 1.1 pk for (i = 0; i < strlen(signature); i++) {
645 1.1 pk ch = bus_space_read_1(iot, ioh, i);
646 1.1 pk if (ch != signature[i])
647 1.1 pk return 0;
648 1.1 pk }
649 1.1 pk
650 1.1 pk /* If card is mapped in high memory (above 15Meg), we can't use it */
651 1.1 pk ch = bus_space_read_1(iot, ioh, EF_MADDR);
652 1.1 pk if (ch & EF_MADDR_HIGH)
653 1.1 pk return 0; /* XXX: maybe we should panic?? */
654 1.1 pk
655 1.1 pk return 1;
656 1.1 pk }
657 1.1 pk
658 1.1 pk struct cfattach ef_ca = {
659 1.1 pk sizeof(struct ef_softc), ef_match, ef_attach
660 1.1 pk };
661 1.1 pk
662