2 * Product specific probe and attach routines for:
3 * 3COM 3C579 and 3C509(in eisa config mode) ethernet controllers
5 * Copyright (c) 1996 Justin T. Gibbs
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice immediately at the beginning of the file, without modification,
13 * this list of conditions, and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Absolutely no warranty of function or purpose is made by the author
19 * 4. Modifications may be freely made to this file if the above conditions
23 #include <sys/cdefs.h>
24 __FBSDID("$FreeBSD$");
26 #include <sys/param.h>
27 #include <sys/systm.h>
28 #include <sys/kernel.h>
29 #include <sys/socket.h>
30 #include <sys/module.h>
33 #include <machine/bus.h>
34 #include <machine/resource.h>
38 #include <net/if_arp.h>
39 #include <net/if_media.h>
41 #include <dev/eisa/eisaconf.h>
43 #include <dev/ep/if_epreg.h>
44 #include <dev/ep/if_epvar.h>
46 #define EISA_DEVICE_ID_3COM_3C509_TP 0x506d5090
47 #define EISA_DEVICE_ID_3COM_3C509_BNC 0x506d5091
48 #define EISA_DEVICE_ID_3COM_3C579_TP 0x506d5092
49 #define EISA_DEVICE_ID_3COM_3C579_BNC 0x506d5093
50 #define EISA_DEVICE_ID_3COM_3C509_COMBO 0x506d5094
51 #define EISA_DEVICE_ID_3COM_3C509_TPO 0x506d5095
53 #define EP_EISA_SLOT_OFFSET 0x0c80
54 #define EP_EISA_IOSIZE 0x000a
56 #define EISA_IOCONF 0x0008
57 #define IRQ_CHANNEL 0xf000
66 #define EISA_BPROM_MEDIA_CONF 0x0006
67 #define TRANS_TYPE 0xc000
68 #define TRANS_TP 0x0000
69 #define TRANS_AUI 0x4000
70 #define TRANS_BNC 0xc000
72 static const char *ep_match(eisa_id_t type);
75 ep_match(eisa_id_t type)
78 case EISA_DEVICE_ID_3COM_3C509_TP:
79 return ("3Com 3C509-TP");
80 case EISA_DEVICE_ID_3COM_3C509_BNC:
81 return ("3Com 3C509-BNC");
82 case EISA_DEVICE_ID_3COM_3C579_TP:
83 return ("3Com 3C579-TP");
84 case EISA_DEVICE_ID_3COM_3C579_BNC:
85 return ("3Com 3C579-BNC");
86 case EISA_DEVICE_ID_3COM_3C509_COMBO:
87 return ("3Com 3C509-Combo");
88 case EISA_DEVICE_ID_3COM_3C509_TPO:
89 return ("3Com 3C509-TPO");
96 ep_eisa_probe(device_t dev)
105 desc = ep_match(eisa_get_id(dev));
108 device_set_desc(dev, desc);
110 port = (eisa_get_slot(dev) * EISA_SLOT_SIZE);
111 iobase = port + EP_EISA_SLOT_OFFSET;
113 /* We must be in EISA configuration mode */
114 if ((inw(iobase + EP_W0_ADDRESS_CFG) & 0x1f) != 0x1f)
117 eisa_add_iospace(dev, iobase, EP_EISA_IOSIZE, RESVADDR_NONE);
118 eisa_add_iospace(dev, port, EP_IOSIZE, RESVADDR_NONE);
120 conf = inw(iobase + EISA_IOCONF);
121 /* Determine our IRQ */
122 switch (conf & IRQ_CHANNEL) {
149 printf("ep: 3COM Network Adapter at "
150 "slot %d has its IRQ disabled. "
156 switch (eisa_get_id(dev)) {
157 case EISA_DEVICE_ID_3COM_3C579_BNC:
158 case EISA_DEVICE_ID_3COM_3C579_TP:
159 int_trig = EISA_TRIGGER_LEVEL;
162 int_trig = EISA_TRIGGER_EDGE;
166 eisa_add_intr(dev, irq, int_trig);
172 ep_eisa_attach(device_t dev)
174 struct ep_softc *sc = device_get_softc(dev);
175 struct resource *eisa_io = NULL;
176 uint32_t eisa_iobase;
182 eisa_io = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
184 device_printf(dev, "No I/O space?!\n");
188 eisa_iobase = rman_get_start(eisa_io);
190 /* Reset and Enable the card */
191 outb(eisa_iobase + EP_W0_CONFIG_CTRL, W0_P4_CMD_RESET_ADAPTER);
192 DELAY(1000); /* we must wait at least 1 ms */
193 outb(eisa_iobase + EP_W0_CONFIG_CTRL, W0_P4_CMD_ENABLE_ADAPTER);
194 /* Now the registers are availible through the lower ioport */
196 if ((error = ep_alloc(dev))) {
197 device_printf(dev, "ep_alloc() failed! (%d)\n", error);
200 switch (eisa_get_id(dev)) {
201 case EISA_DEVICE_ID_3COM_3C579_BNC:
202 case EISA_DEVICE_ID_3COM_3C579_TP:
203 sc->stat = F_ACCESS_32_BITS;
209 irq = rman_get_start(sc->irq);
216 if ((error = ep_attach(sc))) {
217 device_printf(dev, "ep_attach() failed! (%d)\n", error);
220 if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE,
221 NULL, ep_intr, sc, &sc->ep_intrhand))) {
222 device_printf(dev, "bus_setup_intr() failed! (%d)\n", error);
229 bus_release_resource(dev, SYS_RES_IOPORT, 0, eisa_io);
235 static device_method_t ep_eisa_methods[] = {
236 /* Device interface */
237 DEVMETHOD(device_probe, ep_eisa_probe),
238 DEVMETHOD(device_attach, ep_eisa_attach),
239 DEVMETHOD(device_detach, ep_detach),
244 static driver_t ep_eisa_driver = {
247 sizeof(struct ep_softc),
250 extern devclass_t ep_devclass;
252 DRIVER_MODULE(ep, eisa, ep_eisa_driver, ep_devclass, 0, 0);