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