2 * Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
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, this list of conditions and the following disclaimer.
10 * 2. The name of the author may not be used to endorse or promote products
11 * derived from this software without specific prior written permission
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 * DEC PDQ FDDI Controller; code for BSD derived operating systems
33 * This module supports the DEC DEFPA PCI FDDI Controller
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/socket.h>
41 #include <sys/module.h>
44 #include <machine/bus.h>
45 #include <machine/resource.h>
49 #include <net/if_media.h>
52 #include <dev/pci/pcivar.h>
53 #include <dev/pci/pcireg.h>
55 #include <dev/pdq/pdq_freebsd.h>
56 #include <dev/pdq/pdqreg.h>
58 #define DEC_VENDORID 0x1011
59 #define DEFPA_CHIPID 0x000F
61 #define DEFPA_LATENCY 0x88
63 #define PCI_CFLT 0x0C /* Configuration Latency */
64 #define PCI_CBMA 0x10 /* Configuration Base Memory Address */
65 #define PCI_CBIO 0x14 /* Configuration Base I/O Address */
67 static int pdq_pci_probe (device_t);
68 static int pdq_pci_attach (device_t);
69 static int pdq_pci_detach (device_t);
70 static int pdq_pci_shutdown (device_t);
71 static void pdq_pci_ifintr (void *);
74 pdq_pci_ifintr(void *arg)
81 (void) pdq_interrupt(sc->sc_pdq);
88 * This is the PCI configuration support.
91 pdq_pci_probe(device_t dev)
93 if (pci_get_vendor(dev) == DEC_VENDORID &&
94 pci_get_device(dev) == DEFPA_CHIPID) {
95 device_set_desc(dev, "Digital DEFPA PCI FDDI Controller");
96 return (BUS_PROBE_DEFAULT);
103 pdq_pci_attach(device_t dev)
109 sc = device_get_softc(dev);
114 * Map control/status registers.
116 pci_enable_busmaster(dev);
118 command = pci_read_config(dev, PCIR_LATTIMER, 1);
119 if (command < DEFPA_LATENCY) {
120 command = DEFPA_LATENCY;
121 pci_write_config(dev, PCIR_LATTIMER, command, 1);
124 sc->mem_rid = PCI_CBMA;
125 sc->mem_type = SYS_RES_MEMORY;
126 sc->mem = bus_alloc_resource_any(dev, sc->mem_type, &sc->mem_rid,
129 device_printf(dev, "Unable to allocate I/O space resource.\n");
133 sc->mem_bsh = rman_get_bushandle(sc->mem);
134 sc->mem_bst = rman_get_bustag(sc->mem);
137 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid,
138 RF_SHAREABLE | RF_ACTIVE);
140 device_printf(dev, "Unable to allocate interrupt resource.\n");
145 error = pdq_ifattach(sc, sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, PDQ_DEFPA);
149 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE, NULL,
150 pdq_pci_ifintr, sc, &sc->irq_ih);
152 device_printf(dev, "Failed to setup interrupt handler.\n");
170 sc = device_get_softc(dev);
177 pdq_pci_shutdown(device_t dev)
181 sc = device_get_softc(dev);
183 pdq_hwreset(sc->sc_pdq);
189 static device_method_t pdq_pci_methods[] = {
190 /* Device interface */
191 DEVMETHOD(device_probe, pdq_pci_probe),
192 DEVMETHOD(device_attach, pdq_pci_attach),
193 DEVMETHOD(device_detach, pdq_pci_detach),
194 DEVMETHOD(device_shutdown, pdq_pci_shutdown),
199 static driver_t pdq_pci_driver = {
205 DRIVER_MODULE(fpa, pci, pdq_pci_driver, pdq_devclass, 0, 0);
206 MODULE_DEPEND(fpa, pci, 1, 1, 1);
207 MODULE_DEPEND(fpa, fddi, 1, 1, 1);