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