2 * Copyright (c) 1995, David Greenman
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/socket.h>
33 #include <sys/kernel.h>
35 #include <sys/module.h>
37 #include <machine/bus.h>
39 #include <machine/resource.h>
41 #include <net/ethernet.h>
43 #include <net/if_arp.h>
44 #include <net/if_media.h>
45 #include <net/if_mib.h>
47 #include <isa/isavar.h>
49 #include <dev/ed/if_edvar.h>
50 #include <dev/ed/if_edreg.h>
51 #include <dev/ed/if_ed98.h>
53 static int ed98_alloc_port(device_t, int);
54 static int ed98_alloc_memory(device_t, int);
55 static int ed_pio_testmem(struct ed_softc *, int, int, int);
56 static int ed_probe_CNET98(device_t, int, int);
57 static int ed_probe_CNET98EL(device_t, int, int);
58 static int ed_probe_EZ98(device_t, int, int);
59 static int ed_probe_NEC77(device_t, int, int);
60 static int ed_probe_NW98X(device_t, int, int);
61 static int ed_probe_SB98(device_t, int, int);
62 static int ed_probe_SIC98(device_t, int, int);
63 static int ed98_probe_Novell(device_t, int, int);
64 static int ed98_probe_generic8390(struct ed_softc *);
65 static void ed_reset_CNET98(struct ed_softc *, int);
66 static void ed_winsel_CNET98(struct ed_softc *, u_short);
67 static void ed_get_SB98(struct ed_softc *);
69 static int ed_cbus_probe(device_t);
70 static int ed_cbus_attach(device_t);
72 static struct isa_pnp_id ed_ids[] = {
73 /* TODO - list up PnP boards for PC-98 */
78 ed_cbus_probe(device_t dev)
80 struct ed_softc *sc = device_get_softc(dev);
81 int flags = device_get_flags(dev);
84 sc->type = ED_TYPE98(flags);
86 device_printf(dev, "ed_cbus_probe: sc->type=%x\n", sc->type);
89 /* Check isapnp ids */
90 error = ISA_PNP_PROBE(device_get_parent(dev), dev, ed_ids);
92 device_printf(dev, "ed_cbus_probe: ISA_PNP_PROBE returns %d\n", error);
95 /* If the card had a PnP ID that didn't match any we know about */
99 /* If we had some other problem. */
100 if (!(error == 0 || error == ENOENT))
103 /* Heuristic probes */
105 device_printf(dev, "ed_cbus_probe: Heuristic probes start\n");
108 case ED_TYPE98_GENERIC:
111 * sc->type of these boards are overwritten by PC/AT's value.
117 error = ed_probe_EZ98(dev, 0, flags);
121 ed_release_resources(dev);
124 * Allied Telesis CenterCom LA-98-T
126 error = ed_probe_Novell(dev, 0, flags);
128 ed_Novell_read_mac(sc);
134 * NE2000-like boards probe routine
138 * ELECOM LANEED LD-BDN
139 * PLANET SMART COM 98 EN-2298
143 * MELCO LGY-98, IND-SP, IND-SS
148 * ICM DT-ET-25, DT-ET-T5, IF-2766ET, IF-2771ET
149 * D-Link DE-298P, DE-298
154 * Contec C-NET(98)E-A, C-NET(98)L-A
158 * NEC PC-9801-107,108
160 case ED_TYPE98_NC5098:
164 error = ed98_probe_Novell(dev, 0, flags);
168 * other boards with special probe routine
172 * Allied Telesis SIC-98
174 error = ed_probe_SIC98(dev, 0, flags);
177 case ED_TYPE98_CNET98EL:
179 * Contec C-NET(98)E/L
181 error = ed_probe_CNET98EL(dev, 0, flags);
184 case ED_TYPE98_CNET98:
188 error = ed_probe_CNET98(dev, 0, flags);
196 error = ed_probe_NEC77(dev, 0, flags);
199 case ED_TYPE98_NW98X:
203 error = ed_probe_NW98X(dev, 0, flags);
211 error = ed_probe_SB98(dev, 0, flags);
217 device_printf(dev, "ed_cbus_probe: end, error=%d\n", error);
220 error = ed_alloc_irq(dev, 0, 0);
222 ed_release_resources(dev);
230 struct ed_softc *sc = device_get_softc(dev);
231 int flags = device_get_flags(dev);
234 if (sc->port_used > 0) {
235 if (ED_TYPE98(flags) == ED_TYPE98_GENERIC)
236 ed_alloc_port(dev, sc->port_rid, sc->port_used);
238 ed98_alloc_port(dev, sc->port_rid);
241 ed_alloc_memory(dev, sc->mem_rid, sc->mem_used);
243 ed_alloc_irq(dev, sc->irq_rid, 0);
245 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE,
246 NULL, edintr, sc, &sc->irq_handle);
248 ed_release_resources(dev);
252 return ed_attach(dev);
256 * Interrupt conversion table for EtherEZ98
258 static uint16_t ed_EZ98_intr_val[] = {
270 ed_probe_EZ98(device_t dev, int port_rid, int flags)
272 struct ed_softc *sc = device_get_softc(dev);
274 static unsigned short *intr_vals[] = {NULL, ed_EZ98_intr_val};
276 error = ed_alloc_port(dev, port_rid, ED_EZ98_IO_PORTS);
281 sc->asic_offset = ED_EZ98_ASIC_OFFSET;
282 sc->nic_offset = ED_EZ98_NIC_OFFSET;
284 return ed_probe_WD80x3_generic(dev, flags, intr_vals);
288 * I/O conversion tables
291 /* LGY-98, ICM, C-NET(98)E/L */
292 static bus_addr_t ed98_ioaddr_generic[] = {
293 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
297 * Definitions for Contec C-NET(98)E/L
299 #define ED_CNET98EL_ICR 2 /* Interrupt Configuration Register */
301 #define ED_CNET98EL_ICR_IRQ3 0x01
302 #define ED_CNET98EL_ICR_IRQ5 0x02
303 #define ED_CNET98EL_ICR_IRQ6 0x04
304 #define ED_CNET98EL_ICR_IRQ12 0x20
306 #define ED_CNET98EL_IMR 4 /* Interrupt Mask Register */
307 #define ED_CNET98EL_ISR 5 /* Interrupt Status Register */
310 static bus_addr_t ed98_ioaddr_egy98[] = {
311 0, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e,
312 0x100, 0x102, 0x104, 0x106, 0x108, 0x10a, 0x10c, 0x10e
316 static bus_addr_t ed98_ioaddr_sic98[] = {
317 0x0000, 0x0200, 0x0400, 0x0600, 0x0800, 0x0a00, 0x0c00, 0x0e00,
318 0x1000, 0x1200, 0x1400, 0x1600, 0x1800, 0x1a00, 0x1c00, 0x1e00
321 /* LA/T-98, LD-BDN, PC-9801-77, SB-9801 */
322 static bus_addr_t ed98_ioaddr_la98[] = {
323 0x0000, 0x1000, 0x2000, 0x3000, 0x4000, 0x5000, 0x6000, 0x7000,
324 0x8000, 0x9000, 0xa000, 0xb000, 0xc000, 0xd000, 0xe000, 0xf000,
325 0x0100 /* for NEC 77(see below) */
329 * Definitions for NEC PC-9801-77
331 #define ED_NEC77_IRQ 16 /* Interrupt Configuration Register */
333 #define ED_NEC77_IRQ3 0x04
334 #define ED_NEC77_IRQ5 0x06
335 #define ED_NEC77_IRQ6 0x08
336 #define ED_NEC77_IRQ12 0x0a
337 #define ED_NEC77_IRQ13 0x02
340 * Definitions for Soliton SB-9801
342 #define ED_SB98_CFG 1 /* Board configuration */
344 #define ED_SB98_CFG_IRQ3 0x00
345 #define ED_SB98_CFG_IRQ5 0x04
346 #define ED_SB98_CFG_IRQ6 0x08
347 #define ED_SB98_CFG_IRQ12 0x0c
348 #define ED_SB98_CFG_ALTPORT 0x40 /* use EXTERNAL media */
349 #define ED_SB98_CFG_ENABLE 0xa0 /* enable configuration */
351 #define ED_SB98_EEPENA 2 /* EEPROM access enable */
353 #define ED_SB98_EEPENA_DISABLE 0x00
354 #define ED_SB98_EEPENA_ENABLE 0x01
356 #define ED_SB98_EEP 3 /* EEPROM access */
358 #define ED_SB98_EEP_SDA 0x01 /* Serial Data */
359 #define ED_SB98_EEP_SCL 0x02 /* Serial Clock */
360 #define ED_SB98_EEP_READ 0x01 /* Read Command */
362 #define ED_SB98_EEP_DELAY 300
364 #define ED_SB98_ADDRESS 0x01 /* Station Address(1-6) */
366 #define ED_SB98_POLARITY 4 /* Polarity */
369 static bus_addr_t ed98_ioaddr_nec108[] = {
370 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c, 0x000e,
371 0x1000, 0x1002, 0x1004, 0x1006, 0x1008, 0x100a, 0x100c, 0x100e
375 static bus_addr_t ed98_ioaddr_cnet98[] = {
376 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c, 0x000e,
377 0x0400, 0x0402, 0x0404, 0x0406, 0x0408, 0x040a, 0x040c, 0x040e
381 * Definitions for Contec C-NET(98)
383 #define ED_CNET98_MAP_REG0L 0 /* MAPPING register0 Low */
384 #define ED_CNET98_MAP_REG1L 1 /* MAPPING register1 Low */
385 #define ED_CNET98_MAP_REG2L 2 /* MAPPING register2 Low */
386 #define ED_CNET98_MAP_REG3L 3 /* MAPPING register3 Low */
387 #define ED_CNET98_MAP_REG0H 4 /* MAPPING register0 Hi */
388 #define ED_CNET98_MAP_REG1H 5 /* MAPPING register1 Hi */
389 #define ED_CNET98_MAP_REG2H 6 /* MAPPING register2 Hi */
390 #define ED_CNET98_MAP_REG3H 7 /* MAPPING register3 Hi */
391 #define ED_CNET98_WIN_REG 8 /* Window register */
392 #define ED_CNET98_INT_LEV 9 /* Init level register */
394 #define ED_CNET98_INT_IRQ3 0x01 /* INT 0 */
395 #define ED_CNET98_INT_IRQ5 0x02 /* INT 1 */
396 #define ED_CNET98_INT_IRQ6 0x04 /* INT 2 */
397 #define ED_CNET98_INT_IRQ9 0x08 /* INT 3 */
398 #define ED_CNET98_INT_IRQ12 0x20 /* INT 5 */
399 #define ED_CNET98_INT_IRQ13 0x40 /* INT 6 */
401 #define ED_CNET98_INT_REQ 10 /* Init request register */
402 #define ED_CNET98_INT_MASK 11 /* Init mask register */
403 #define ED_CNET98_INT_STAT 12 /* Init status register */
404 #define ED_CNET98_INT_CLR 12 /* Init clear register */
405 #define ED_CNET98_RESERVE1 13
406 #define ED_CNET98_RESERVE2 14
407 #define ED_CNET98_RESERVE3 15
409 /* EC/EP-98X, NC5098 */
410 static bus_addr_t ed98_ioaddr_nw98x[] = {
411 0x0000, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, 0x0700,
412 0x0800, 0x0900, 0x0a00, 0x0b00, 0x0c00, 0x0d00, 0x0e00, 0x0f00,
413 0x1000 /* for EC/EP-98X(see below) */
417 * Definitions for Networld EC/EP-98X
419 #define ED_NW98X_IRQ 16 /* Interrupt Configuration Register */
421 #define ED_NW98X_IRQ3 0x04
422 #define ED_NW98X_IRQ5 0x06
423 #define ED_NW98X_IRQ6 0x08
424 #define ED_NW98X_IRQ12 0x0a
425 #define ED_NW98X_IRQ13 0x02
428 static bus_addr_t ed98_asic_nc5098[] = {
429 /* DATA ENADDR RESET */
430 0x0000, 0x2000, 0x2100, 0x2200, 0x2300, 0x2400, 0x2500, 0x4000,
431 0, 0, 0, 0, 0, 0, 0, 0
435 * Definitions for NextCom NC5098
437 #define ED_NC5098_ENADDR 1 /* Station Address(1-6) */
440 * Allocate a port resource with the given resource id.
443 ed98_alloc_port(device_t dev, int rid)
445 struct ed_softc *sc = device_get_softc(dev);
446 struct resource *res;
448 bus_addr_t *io_nic, *io_asic, adj;
449 static bus_addr_t io_res[ED_NOVELL_IO_PORTS + 1];
451 int offset, reset, data;
453 /* Set i/o table for resource manager */
454 io_nic = io_asic = ed98_ioaddr_generic;
455 offset = ED_NOVELL_ASIC_OFFSET;
456 reset = ED_NOVELL_RESET;
457 data = ED_NOVELL_DATA;
458 n = ED_NOVELL_IO_PORTS;
462 io_asic = ed98_ioaddr_egy98; /* XXX - Yes, we use egy98 */
468 io_nic = io_asic = ed98_ioaddr_egy98;
478 io_nic = io_asic = ed98_ioaddr_la98;
484 io_nic = io_asic = ed98_ioaddr_sic98;
490 io_nic = io_asic = ed98_ioaddr_nec108;
491 offset = 0x0888; /* XXX - overwritten after */
493 n = 16; /* XXX - does not set ASIC i/o here */
497 io_nic = io_asic = ed98_ioaddr_la98;
501 case ED_TYPE98_CNET98EL:
506 case ED_TYPE98_CNET98:
507 /* XXX - Yes, we use generic i/o here */
511 case ED_TYPE98_NW98X:
512 io_nic = io_asic = ed98_ioaddr_nw98x;
517 io_nic = io_asic = ed98_ioaddr_la98;
522 case ED_TYPE98_NC5098:
523 io_nic = ed98_ioaddr_nw98x;
524 io_asic = ed98_asic_nc5098;
531 bcopy(io_nic, io_res, sizeof(io_nic[0]) * ED_NOVELL_ASIC_OFFSET);
532 for (i = ED_NOVELL_ASIC_OFFSET; i < ED_NOVELL_IO_PORTS; i++)
533 io_res[i] = io_asic[i - ED_NOVELL_ASIC_OFFSET] + offset;
535 res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, io_res, n,
543 sc->port_bst = rman_get_bustag(res);
544 sc->port_bsh = rman_get_bushandle(res);
546 /* Re-map i/o table if needed */
549 case ED_TYPE98_NW98X:
550 io_res[n] = io_asic[n - ED_NOVELL_ASIC_OFFSET] + offset;
555 adj = (rman_get_start(res) & 0xf000) / 2;
556 offset = (offset | adj) - rman_get_start(res);
558 for (n = ED_NOVELL_ASIC_OFFSET; n < ED_NOVELL_IO_PORTS; n++)
559 io_res[n] = io_asic[n - ED_NOVELL_ASIC_OFFSET] + offset;
562 case ED_TYPE98_CNET98:
563 io_nic = io_asic = ed98_ioaddr_cnet98;
566 bcopy(io_nic, io_res, sizeof(io_nic[0]) * ED_NOVELL_ASIC_OFFSET);
567 for (n = ED_NOVELL_ASIC_OFFSET; n < ED_NOVELL_IO_PORTS; n++)
568 io_res[n] = io_asic[n - ED_NOVELL_ASIC_OFFSET] + offset;
571 case ED_TYPE98_NC5098:
572 n = ED_NOVELL_IO_PORTS;
576 if (reset != ED_NOVELL_RESET)
577 io_res[ED_NOVELL_ASIC_OFFSET + ED_NOVELL_RESET] =
578 io_res[ED_NOVELL_ASIC_OFFSET + reset];
579 if (data != ED_NOVELL_DATA) {
580 io_res[ED_NOVELL_ASIC_OFFSET + ED_NOVELL_DATA] =
581 io_res[ED_NOVELL_ASIC_OFFSET + data];
583 io_res[ED_NOVELL_ASIC_OFFSET + ED_NOVELL_DATA + 1] =
584 io_res[ED_NOVELL_ASIC_OFFSET + data + 1];
588 error = isa_load_resourcev(res, io_res, n);
592 device_printf(dev, "ed98_alloc_port: i/o ports = %d\n", n);
593 for (i = 0; i < n; i++)
594 printf("%x,", io_res[i]);
601 ed98_alloc_memory(dev, rid)
605 struct ed_softc *sc = device_get_softc(dev);
607 u_long conf_maddr, conf_msize;
609 error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &conf_maddr,
614 if ((conf_maddr == 0) || (conf_msize == 0))
617 error = ed_alloc_memory(dev, rid, (int) conf_msize);
622 sc->mem_size = conf_msize;
628 * Generic probe routine for testing for the existance of a DS8390.
629 * Must be called after the NIC has just been reset. This routine
630 * works by looking at certain register values that are guaranteed
631 * to be initialized a certain way after power-up or reset. Seems
632 * not to currently work on the 83C690.
636 * Register reset bits set bits
637 * Command Register (CR) TXP, STA RD2, STP
638 * Interrupt Status (ISR) RST
639 * Interrupt Mask (IMR) All bits
640 * Data Control (DCR) LAS
641 * Transmit Config. (TCR) LB1, LB0
643 * XXX - We only check the CR register.
645 * Return 1 if 8390 was found, 0 if not.
649 ed98_probe_generic8390(struct ed_softc *sc)
651 u_char tmp = ed_nic_inb(sc, ED_P0_CR);
653 printf("ed?: inb(ED_P0_CR)=%x\n", tmp);
655 if ((tmp & (ED_CR_RD2 | ED_CR_TXP | ED_CR_STA | ED_CR_STP)) !=
656 (ED_CR_RD2 | ED_CR_STP))
659 (void) ed_nic_inb(sc, ED_P0_ISR);
665 ed98_probe_Novell(device_t dev, int port_rid, int flags)
667 struct ed_softc *sc = device_get_softc(dev);
670 u_char romdata[ETHER_ADDR_LEN * 2], tmp;
673 device_printf(dev, "ed98_probe_Novell: start\n");
675 error = ed98_alloc_port(dev, port_rid);
679 sc->asic_offset = ED_NOVELL_ASIC_OFFSET;
680 sc->nic_offset = ED_NOVELL_NIC_OFFSET;
682 /* Reset the board */
684 device_printf(dev, "ed98_probe_Novell: reset\n");
687 #if 1 /* XXX - I'm not sure this is really necessary... */
689 tmp = ed_asic_inb(sc, ED_NOVELL_RESET);
690 ed_asic_outb(sc, ED_NOVELL_RESET, (tmp & 0xf0) | 0x08);
691 ed_nic_outb(sc, 0x04, tmp);
692 (void) ed_asic_inb(sc, 0x08);
693 ed_asic_outb(sc, 0x08, tmp);
694 ed_asic_outb(sc, 0x08, tmp & 0x7f);
697 case ED_TYPE98_NC5098:
698 ed_asic_outb(sc, ED_NOVELL_RESET, 0x00);
700 ed_asic_outb(sc, ED_NOVELL_RESET, 0x01);
704 tmp = ed_asic_inb(sc, ED_NOVELL_RESET);
707 * I don't know if this is necessary; probably cruft leftover from
708 * Clarkson packet driver code. Doesn't do a thing on the boards I've
709 * tested. -DG [note that an outb(0x84, 0) seems to work here, and is
710 * non-invasive...but some boards don't seem to reset and I don't have
711 * complete documentation on what the 'right' thing to do is...so we
712 * do the invasive thing for now. Yuck.]
714 ed_asic_outb(sc, ED_NOVELL_RESET, tmp);
720 * This is needed because some NE clones apparently don't reset the
721 * NIC properly (or the NIC chip doesn't reset fully on power-up) XXX
722 * - this makes the probe invasive! ...Done against my better
725 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP);
728 /* Make sure that we really have an 8390 based board */
729 if (!ed98_probe_generic8390(sc))
732 /* Test memory via PIO */
734 device_printf(dev, "ed98_probe_Novell: test memory\n");
736 sc->cr_proto = ED_CR_RD2;
737 if (!ed_pio_testmem(sc, 8192, 0, flags) &&
738 !ed_pio_testmem(sc, 16384, 1, flags))
741 /* Setup the board type */
743 device_printf(dev, "ed98_probe_Novell: board type\n");
747 sc->type_str = "LD-BDN";
750 sc->type_str = "EGY-98";
753 sc->type_str = "LGY-98";
756 sc->type_str = "ICM";
759 sc->type_str = "PC-9801-108";
762 sc->type_str = "LA-98";
764 case ED_TYPE98_NW98X:
765 sc->type_str = "NW98X";
767 case ED_TYPE98_NC5098:
768 sc->type_str = "NC5098";
775 /* Get station address */
777 case ED_TYPE98_NC5098:
778 for (n = 0; n < ETHER_ADDR_LEN; n++)
779 sc->enaddr[n] = ed_asic_inb(sc, ED_NC5098_ENADDR + n);
783 ed_pio_readmem(sc, 0, romdata, sizeof(romdata));
784 for (n = 0; n < ETHER_ADDR_LEN; n++)
785 sc->enaddr[n] = romdata[n * (sc->isa16bit + 1)];
789 /* clear any pending interrupts that might have occurred above */
790 ed_nic_outb(sc, ED_P0_ISR, 0xff);
792 sc->sc_write_mbufs = ed_pio_write_mbufs;
797 * Probe and vendor-specific initialization routine for SIC-98 boards
800 ed_probe_SIC98(device_t dev, int port_rid, int flags)
802 struct ed_softc *sc = device_get_softc(dev);
808 * Setup card RAM and I/O address
809 * Kernel Virtual to segment C0000-DFFFF????
811 error = ed98_alloc_port(dev, port_rid);
815 sc->asic_offset = ED_SIC_ASIC_OFFSET;
816 sc->nic_offset = ED_SIC_NIC_OFFSET;
818 error = ed98_alloc_memory(dev, 0);
822 /* Reset card to force it into a known state. */
823 ed_asic_outb(sc, 0, 0x00);
825 if (ED_TYPE98SUB(flags) == 0) {
827 ed_asic_outb(sc, 0, 0x94);
829 ed_asic_outb(sc, 0, 0x94);
832 ed_asic_outb(sc, 0, 0x80);
834 ed_asic_outb(sc, 0, 0x94);
836 ed_asic_outb(sc, 0, 0x9e);
841 * Here we check the card ROM, if the checksum passes, and the
842 * type code and ethernet address check out, then we know we have
845 sum = bus_space_read_1(sc->mem_bst, sc->mem_bsh, 6 * 2);
846 for (i = 0; i < ETHER_ADDR_LEN; i++)
847 sum ^= (sc->enaddr[i] =
848 bus_space_read_1(sc->mem_bst, sc->mem_bsh, i * 2));
850 device_printf(dev, "ed_probe_sic98: got address %6D\n",
855 if ((sc->enaddr[0] | sc->enaddr[1] | sc->enaddr[2]) == 0)
858 sc->vendor = ED_VENDOR_SIC;
859 sc->type_str = "SIC98";
864 * SIC RAM page 0x0000-0x3fff(or 0x7fff)
866 if (ED_TYPE98SUB(flags) == 0)
867 ed_asic_outb(sc, 0, 0x90);
869 ed_asic_outb(sc, 0, 0x8e);
872 error = ed_clear_memory(dev);
877 sc->mem_end = sc->mem_start + sc->mem_size;
880 * allocate one xmit buffer if < 16k, two buffers otherwise
882 if ((sc->mem_size < 16384) || (flags & ED_FLAGS_NO_MULTI_BUFFERING))
886 sc->tx_page_start = 0;
888 sc->rec_page_start = sc->tx_page_start + ED_TXBUF_SIZE * sc->txb_cnt;
889 sc->rec_page_stop = sc->tx_page_start + sc->mem_size / ED_PAGE_SIZE;
891 sc->mem_ring = sc->mem_start + sc->txb_cnt * ED_PAGE_SIZE * ED_TXBUF_SIZE;
893 sc->sc_write_mbufs = ed_shmem_write_mbufs;
898 * Contec C-NET(98) series support routines
901 ed_reset_CNET98(struct ed_softc *sc, int flags)
903 u_int init_addr = ED_CNET98_INIT;
906 /* Choose initial register address */
907 if (ED_TYPE98SUB(flags) != 0) {
908 init_addr = ED_CNET98_INIT2;
911 printf("ed?: initial register=%x\n", init_addr);
914 * Reset the board to force it into a known state.
916 outb(init_addr, 0x00); /* request */
918 outb(init_addr, 0x01); /* cancel */
922 * Set I/O address(A15-12) and cpu type
925 * AAAA: A15-A12, I: I/O enable, XX: reserved, C: CPU type
927 * CPU type is 1:80286 or higher, 0:not.
928 * But FreeBSD runs under i386 or higher, thus it must be 1.
930 tmp = (rman_get_start(sc->port_res) & 0xf000) >> 8;
931 tmp |= (0x08 | 0x01);
933 printf("ed?: outb(%x, %x)\n", init_addr + 2, tmp);
935 outb(init_addr + 2, tmp);
939 * This is needed because some NE clones apparently don't reset the
940 * NIC properly (or the NIC chip doesn't reset fully on power-up) XXX
941 * - this makes the probe invasive! ...Done against my better
944 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP);
949 ed_winsel_CNET98(struct ed_softc *sc, u_short bank)
951 u_char mem = (rman_get_start(sc->mem_res) >> 12) & 0xff;
954 * Disable window memory
957 ed_asic_outb(sc, ED_CNET98_WIN_REG, mem & 0x7f);
961 * Select window address
962 * FreeBSD address 0xf00xxxxx
964 ed_asic_outb(sc, ED_CNET98_MAP_REG0L, bank & 0xff);
966 ed_asic_outb(sc, ED_CNET98_MAP_REG0H, (bank >> 8) & 0xff);
968 ed_asic_outb(sc, ED_CNET98_MAP_REG1L, 0x00);
970 ed_asic_outb(sc, ED_CNET98_MAP_REG1H, 0x41);
972 ed_asic_outb(sc, ED_CNET98_MAP_REG2L, 0x00);
974 ed_asic_outb(sc, ED_CNET98_MAP_REG2H, 0x42);
976 ed_asic_outb(sc, ED_CNET98_MAP_REG3L, 0x00);
978 ed_asic_outb(sc, ED_CNET98_MAP_REG3H, 0x43);
982 * Enable window memory(16Kbyte)
986 printf("ed?: window start address=%x\n", mem);
988 ed_asic_outb(sc, ED_CNET98_WIN_REG, mem);
993 * Probe and vendor-specific initialization routine for C-NET(98) boards
996 ed_probe_CNET98(device_t dev, int port_rid, int flags)
998 struct ed_softc *sc = device_get_softc(dev);
1001 u_long conf_irq, junk;
1006 error = ed98_alloc_port(dev, port_rid);
1010 sc->asic_offset = ED_NOVELL_ASIC_OFFSET;
1011 sc->nic_offset = ED_NOVELL_NIC_OFFSET;
1013 error = ed98_alloc_memory(dev, 0);
1017 /* Check I/O address. 0x[a-f]3d0 are allowed. */
1018 if (((rman_get_start(sc->port_res) & 0x0fff) != 0x03d0)
1019 || ((rman_get_start(sc->port_res) & 0xf000) < (u_short) 0xa000)) {
1021 device_printf(dev, "Invalid i/o port configuration (0x%lx) "
1022 "must be %s for %s\n", rman_get_start(sc->port_res),
1023 "0x[a-f]3d0", "CNET98");
1029 /* Check window area address */
1030 tmp_s = rman_get_start(sc->mem_res) >> 12;
1032 device_printf(dev, "Please change window address(0x%lx)\n",
1033 rman_get_start(sc->mem_res));
1038 tmp = rman_get_start(sc->port_res) >> 12;
1039 if ((tmp_s <= tmp) && (tmp < (tmp_s + 4))) {
1040 device_printf(dev, "Please change iobase address(0x%lx) "
1041 "or window address(0x%lx)\n",
1042 rman_get_start(sc->port_res),
1043 rman_get_start(sc->mem_res));
1047 /* Reset the board */
1048 ed_reset_CNET98(sc, flags);
1051 * This is needed because some NE clones apparently don't reset the
1052 * NIC properly (or the NIC chip doesn't reset fully on power-up) XXX
1053 * - this makes the probe invasive! ...Done against my better
1056 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP);
1059 /* Make sure that we really have an 8390 based board */
1060 if (!ed98_probe_generic8390(sc))
1064 * Set window ethernet address area
1065 * board memory base 0x480000 data 256byte
1067 ed_winsel_CNET98(sc, 0x4800);
1070 * Get station address from on-board ROM
1072 bus_space_read_region_1(sc->mem_bst, sc->mem_bsh, sc->mem_start,
1073 sc->enaddr, ETHER_ADDR_LEN);
1075 sc->vendor = ED_VENDOR_MISC;
1076 sc->type_str = "CNET98";
1078 sc->cr_proto = ED_CR_RD2;
1081 * Set window buffer memory area
1082 * board memory base 0x400000 data 16kbyte
1084 ed_winsel_CNET98(sc, 0x4000);
1086 error = ed_clear_memory(dev);
1091 sc->mem_end = sc->mem_start + sc->mem_size;
1093 sc->txb_cnt = 1; /* XXX */
1094 sc->tx_page_start = 0;
1096 sc->rec_page_start = sc->tx_page_start + ED_TXBUF_SIZE;
1097 sc->rec_page_stop = sc->tx_page_start + sc->mem_size / ED_PAGE_SIZE;
1099 sc->mem_ring = sc->mem_start + ED_PAGE_SIZE * ED_TXBUF_SIZE;
1102 * Set interrupt level
1104 error = bus_get_resource(dev, SYS_RES_IRQ, 0, &conf_irq, &junk);
1110 tmp = ED_CNET98_INT_IRQ3;
1113 tmp = ED_CNET98_INT_IRQ5;
1116 tmp = ED_CNET98_INT_IRQ6;
1119 tmp = ED_CNET98_INT_IRQ9;
1122 tmp = ED_CNET98_INT_IRQ12;
1125 tmp = ED_CNET98_INT_IRQ13;
1128 device_printf(dev, "Invalid irq configuration (%ld) must be "
1129 "%s for %s\n", conf_irq, "3,5,6,9,12,13", "CNET98");
1132 ed_asic_outb(sc, ED_CNET98_INT_LEV, tmp);
1135 * Set interrupt mask.
1136 * bit7:1 all interrupt mask
1137 * bit1:1 timer interrupt mask
1138 * bit0:0 NS controler interrupt enable
1140 ed_asic_outb(sc, ED_CNET98_INT_MASK, 0x7e);
1143 sc->sc_write_mbufs = ed_shmem_write_mbufs;
1148 * Probe and vendor-specific initialization routine for C-NET(98)E/L boards
1151 ed_probe_CNET98EL(device_t dev, int port_rid, int flags)
1153 struct ed_softc *sc = device_get_softc(dev);
1156 u_char romdata[ETHER_ADDR_LEN * 2], tmp;
1157 u_long conf_irq, junk;
1159 error = ed98_alloc_port(dev, port_rid);
1163 sc->asic_offset = ED_NOVELL_ASIC_OFFSET;
1164 sc->nic_offset = ED_NOVELL_NIC_OFFSET;
1166 /* Check I/O address. 0x[0-f]3d0 are allowed. */
1167 if ((rman_get_start(sc->port_res) & 0x0fff) != 0x03d0) {
1169 device_printf(dev, "Invalid i/o port configuration (0x%lx) "
1170 "must be %s for %s\n", rman_get_start(sc->port_res),
1171 "0x?3d0", "CNET98E/L");
1176 /* Reset the board */
1177 ed_reset_CNET98(sc, flags);
1180 * This is needed because some NE clones apparently don't reset the
1181 * NIC properly (or the NIC chip doesn't reset fully on power-up) XXX
1182 * - this makes the probe invasive! ...Done against my better
1185 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP);
1188 /* Make sure that we really have an 8390 based board */
1189 if (!ed98_probe_generic8390(sc))
1192 /* Test memory via PIO */
1193 sc->cr_proto = ED_CR_RD2;
1194 if (!ed_pio_testmem(sc, ED_CNET98EL_PAGE_OFFSET, 1, flags))
1197 /* This looks like a C-NET(98)E/L board. */
1198 sc->type_str = "CNET98E/L";
1201 * Set IRQ. C-NET(98)E/L only allows a choice of irq 3,5,6.
1203 error = bus_get_resource(dev, SYS_RES_IRQ, 0, &conf_irq, &junk);
1209 tmp = ED_CNET98EL_ICR_IRQ3;
1212 tmp = ED_CNET98EL_ICR_IRQ5;
1215 tmp = ED_CNET98EL_ICR_IRQ6;
1219 tmp = ED_CNET98EL_ICR_IRQ12;
1223 device_printf(dev, "Invalid irq configuration (%ld) must be "
1224 "%s for %s\n", conf_irq, "3,5,6", "CNET98E/L");
1227 ed_asic_outb(sc, ED_CNET98EL_ICR, tmp);
1228 ed_asic_outb(sc, ED_CNET98EL_IMR, 0x7e);
1230 /* Get station address from on-board ROM */
1231 ed_pio_readmem(sc, 16384, romdata, sizeof(romdata));
1232 for (i = 0; i < ETHER_ADDR_LEN; i++)
1233 sc->enaddr[i] = romdata[i * 2];
1235 /* clear any pending interrupts that might have occurred above */
1236 ed_nic_outb(sc, ED_P0_ISR, 0xff);
1238 sc->sc_write_mbufs = ed_pio_write_mbufs;
1243 * Probe and vendor-specific initialization routine for PC-9801-77 boards
1246 ed_probe_NEC77(device_t dev, int port_rid, int flags)
1248 struct ed_softc *sc = device_get_softc(dev);
1251 u_long conf_irq, junk;
1253 error = ed98_probe_Novell(dev, port_rid, flags);
1257 /* LA/T-98 does not need IRQ setting. */
1258 if (ED_TYPE98SUB(flags) == 0)
1262 * Set IRQ. PC-9801-77 only allows a choice of irq 3,5,6,12,13.
1264 error = bus_get_resource(dev, SYS_RES_IRQ, 0, &conf_irq, &junk);
1270 tmp = ED_NEC77_IRQ3;
1273 tmp = ED_NEC77_IRQ5;
1276 tmp = ED_NEC77_IRQ6;
1279 tmp = ED_NEC77_IRQ12;
1282 tmp = ED_NEC77_IRQ13;
1285 device_printf(dev, "Invalid irq configuration (%ld) must be "
1286 "%s for %s\n", conf_irq, "3,5,6,12,13", "PC-9801-77");
1289 ed_asic_outb(sc, ED_NEC77_IRQ, tmp);
1295 * Probe and vendor-specific initialization routine for EC/EP-98X boards
1298 ed_probe_NW98X(device_t dev, int port_rid, int flags)
1300 struct ed_softc *sc = device_get_softc(dev);
1303 u_long conf_irq, junk;
1305 error = ed98_probe_Novell(dev, port_rid, flags);
1309 /* Networld 98X3 does not need IRQ setting. */
1310 if (ED_TYPE98SUB(flags) == 0)
1314 * Set IRQ. EC/EP-98X only allows a choice of irq 3,5,6,12,13.
1316 error = bus_get_resource(dev, SYS_RES_IRQ, 0, &conf_irq, &junk);
1322 tmp = ED_NW98X_IRQ3;
1325 tmp = ED_NW98X_IRQ5;
1328 tmp = ED_NW98X_IRQ6;
1331 tmp = ED_NW98X_IRQ12;
1334 tmp = ED_NW98X_IRQ13;
1337 device_printf(dev, "Invalid irq configuration (%ld) must be "
1338 "%s for %s\n", conf_irq, "3,5,6,12,13", "EC/EP-98X");
1341 ed_asic_outb(sc, ED_NW98X_IRQ, tmp);
1347 * Read SB-9801 station address from Serial Two-Wire EEPROM
1350 ed_get_SB98(struct ed_softc *sc)
1355 /* enable EEPROM acceess */
1356 ed_asic_outb(sc, ED_SB98_EEPENA, ED_SB98_EEPENA_ENABLE);
1358 /* output start command */
1359 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SDA | ED_SB98_EEP_SCL);
1360 DELAY(ED_SB98_EEP_DELAY);
1361 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SCL);
1362 DELAY(ED_SB98_EEP_DELAY);
1364 /* output address (7bit) */
1365 for (mask = 0x40; mask != 0; mask >>= 1) {
1367 if (ED_SB98_ADDRESS & mask)
1368 val = ED_SB98_EEP_SDA;
1369 ed_asic_outb(sc, ED_SB98_EEP, val);
1370 DELAY(ED_SB98_EEP_DELAY);
1371 ed_asic_outb(sc, ED_SB98_EEP, val | ED_SB98_EEP_SCL);
1372 DELAY(ED_SB98_EEP_DELAY);
1375 /* output READ command */
1376 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_READ);
1377 DELAY(ED_SB98_EEP_DELAY);
1378 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_READ | ED_SB98_EEP_SCL);
1379 DELAY(ED_SB98_EEP_DELAY);
1381 /* read station address */
1382 for (i = 0; i < ETHER_ADDR_LEN; i++) {
1384 ed_asic_outb(sc, ED_SB98_EEP, 0);
1385 DELAY(ED_SB98_EEP_DELAY);
1386 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SCL);
1387 DELAY(ED_SB98_EEP_DELAY);
1390 for (j = 0; j < 8; j++) {
1391 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SDA);
1392 DELAY(ED_SB98_EEP_DELAY);
1393 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SDA | ED_SB98_EEP_SCL);
1394 DELAY(ED_SB98_EEP_DELAY);
1396 val |= (ed_asic_inb(sc, ED_SB98_EEP) & ED_SB98_EEP_SDA);
1397 DELAY(ED_SB98_EEP_DELAY);
1399 sc->enaddr[i] = val;
1402 /* output Last ACK */
1403 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SDA);
1404 DELAY(ED_SB98_EEP_DELAY);
1405 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SDA | ED_SB98_EEP_SCL);
1406 DELAY(ED_SB98_EEP_DELAY);
1408 /* output stop command */
1409 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SCL);
1410 DELAY(ED_SB98_EEP_DELAY);
1411 ed_asic_outb(sc, ED_SB98_EEP, ED_SB98_EEP_SDA | ED_SB98_EEP_SCL);
1412 DELAY(ED_SB98_EEP_DELAY);
1414 /* disable EEPROM access */
1415 ed_asic_outb(sc, ED_SB98_EEPENA, ED_SB98_EEPENA_DISABLE);
1419 * Probe and vendor-specific initialization routine for SB-9801 boards
1422 ed_probe_SB98(device_t dev, int port_rid, int flags)
1424 struct ed_softc *sc = device_get_softc(dev);
1427 u_long conf_irq, junk;
1429 error = ed98_alloc_port(dev, port_rid);
1433 sc->asic_offset = ED_NOVELL_ASIC_OFFSET;
1434 sc->nic_offset = ED_NOVELL_NIC_OFFSET;
1436 /* Check I/O address. 00d[02468ace] are allowed. */
1437 if ((rman_get_start(sc->port_res) & ~0x000e) != 0x00d0) {
1439 device_printf(dev, "Invalid i/o port configuration (0x%lx) "
1440 "must be %s for %s\n", rman_get_start(sc->port_res),
1446 /* Write I/O port address and read 4 times */
1447 outb(ED_SB98_IO_INHIBIT, rman_get_start(sc->port_res) & 0xff);
1448 (void) inb(ED_SB98_IO_INHIBIT); DELAY(300);
1449 (void) inb(ED_SB98_IO_INHIBIT); DELAY(300);
1450 (void) inb(ED_SB98_IO_INHIBIT); DELAY(300);
1451 (void) inb(ED_SB98_IO_INHIBIT); DELAY(300);
1454 * Check IRQ. Soliton SB-9801 only allows a choice of
1457 error = bus_get_resource(dev, SYS_RES_IRQ, 0, &conf_irq, &junk);
1463 tmp = ED_SB98_CFG_IRQ3;
1466 tmp = ED_SB98_CFG_IRQ5;
1469 tmp = ED_SB98_CFG_IRQ6;
1472 tmp = ED_SB98_CFG_IRQ12;
1475 device_printf(dev, "Invalid irq configuration (%ld) must be "
1476 "%s for %s\n", conf_irq, "3,5,6,12", "SB9801");
1480 if (flags & ED_FLAGS_DISABLE_TRANCEIVER)
1481 tmp |= ED_SB98_CFG_ALTPORT;
1482 ed_asic_outb(sc, ED_SB98_CFG, ED_SB98_CFG_ENABLE | tmp);
1483 ed_asic_outb(sc, ED_SB98_POLARITY, 0x01);
1485 /* Reset the board. */
1486 ed_asic_outb(sc, ED_NOVELL_RESET, 0x7a);
1488 ed_asic_outb(sc, ED_NOVELL_RESET, 0x79);
1492 * This is needed because some NE clones apparently don't reset the
1493 * NIC properly (or the NIC chip doesn't reset fully on power-up) XXX
1494 * - this makes the probe invasive! ...Done against my better
1497 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP);
1500 /* Make sure that we really have an 8390 based board */
1501 if (!ed98_probe_generic8390(sc))
1504 /* Test memory via PIO */
1505 sc->cr_proto = ED_CR_RD2;
1506 if (!ed_pio_testmem(sc, 16384, 1, flags))
1509 /* This looks like an SB9801 board. */
1510 sc->type_str = "SB9801";
1512 /* Get station address */
1515 /* clear any pending interrupts that might have occurred above */
1516 ed_nic_outb(sc, ED_P0_ISR, 0xff);
1518 sc->sc_write_mbufs = ed_pio_write_mbufs;
1523 * Test the ability to read and write to the NIC memory.
1526 ed_pio_testmem(struct ed_softc *sc, int page_offset, int isa16bit, int flags)
1529 static char test_pattern[32] = "THIS is A memory TEST pattern";
1530 char test_buffer[32];
1535 sc->vendor = ED_VENDOR_NOVELL;
1537 sc->isa16bit = isa16bit;
1539 /* 8k of memory plus an additional 8k if 16bit */
1540 memsize = (isa16bit ? 16384 : 8192);
1543 * This prevents packets from being stored in the NIC memory when the
1544 * readmem routine turns on the start bit in the CR.
1546 ed_nic_outb(sc, ED_P0_RCR, ED_RCR_MON);
1548 /* Initialize DCR for byte/word operations */
1550 ed_nic_outb(sc, ED_P0_DCR, ED_DCR_WTS | ED_DCR_FT1 | ED_DCR_LS);
1552 ed_nic_outb(sc, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS);
1553 ed_nic_outb(sc, ED_P0_PSTART, page_offset / ED_PAGE_SIZE);
1554 ed_nic_outb(sc, ED_P0_PSTOP, (page_offset + memsize) / ED_PAGE_SIZE);
1556 printf("ed?: ed_pio_testmem: page start=%x, end=%lx",
1557 page_offset, page_offset + memsize);
1561 * Write a test pattern. If this fails, then we don't know
1562 * what this board is.
1564 ed_pio_writemem(sc, test_pattern, page_offset, sizeof(test_pattern));
1565 ed_pio_readmem(sc, page_offset, test_buffer, sizeof(test_pattern));
1567 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern))) {
1569 printf("ed?: ed_pio_testmem: bcmp(page %x) NG", page_offset);
1575 /* Check the bottom. */
1576 page_end = page_offset + memsize - ED_PAGE_SIZE;
1577 ed_pio_writemem(sc, test_pattern, page_end, sizeof(test_pattern));
1578 ed_pio_readmem(sc, page_end, test_buffer, sizeof(test_pattern));
1580 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern))) {
1582 printf("ed?: ed_pio_testmem: bcmp(page %x) NG", page_end);
1587 sc->mem_size = memsize;
1588 sc->mem_start = page_offset;
1589 sc->mem_end = sc->mem_start + memsize;
1590 sc->tx_page_start = page_offset / ED_PAGE_SIZE;
1593 * Use one xmit buffer if < 16k, two buffers otherwise (if not told
1596 if ((memsize < 16384) || (flags & ED_FLAGS_NO_MULTI_BUFFERING))
1601 sc->rec_page_start = sc->tx_page_start + sc->txb_cnt * ED_TXBUF_SIZE;
1602 sc->rec_page_stop = sc->tx_page_start + memsize / ED_PAGE_SIZE;
1604 sc->mem_ring = sc->mem_start + sc->txb_cnt * ED_PAGE_SIZE * ED_TXBUF_SIZE;
1609 static device_method_t ed_cbus_methods[] = {
1610 /* Device interface */
1611 DEVMETHOD(device_probe, ed_cbus_probe),
1612 DEVMETHOD(device_attach, ed_cbus_attach),
1613 DEVMETHOD(device_detach, ed_detach),
1618 static driver_t ed_cbus_driver = {
1621 sizeof(struct ed_softc)
1624 DRIVER_MODULE(ed, isa, ed_cbus_driver, ed_devclass, 0, 0);
1625 MODULE_DEPEND(ed, isa, 1, 1, 1);
1626 MODULE_DEPEND(ed, ether, 1, 1, 1);