Deleted Added
sdiff udiff text old ( 70594 ) new ( 93383 )
full compact
1/*-
2 * Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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 withough specific prior written permission
12 *
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.
23 *
24 * $FreeBSD: head/sys/dev/pdq/if_fpa.c 70594 2001-01-02 09:30:48Z peter $
25 *
26 */
27
28/*
29 * DEC PDQ FDDI Controller; code for BSD derived operating systems
30 *
31 * This module supports the DEC DEFPA PCI FDDI Controller
32 */
33
34#include <sys/param.h>
35#include <sys/kernel.h>
36#include <sys/socket.h>
37
38#include <net/if.h>
39
40#include <net/ethernet.h>
41#include <net/if_arp.h>
42#include <dev/pdq/pdqvar.h>
43#include <dev/pdq/pdqreg.h>
44#include <machine/bus.h>
45#include <machine/resource.h>
46#include <sys/bus.h>
47#include <sys/rman.h>
48#include <pci/pcivar.h>
49#include <pci/pcireg.h>
50
51
52#define DEC_VENDORID 0x1011
53#define DEFPA_CHIPID 0x000F
54
55#define DEFPA_LATENCY 0x88
56
57#define PCI_CFLT 0x0C /* Configuration Latency */
58#define PCI_CBMA 0x10 /* Configuration Base Memory Address */
59#define PCI_CBIO 0x14 /* Configuration Base I/O Address */
60
61static void
62pdq_pci_ifintr(void *arg)
63{
64 pdq_softc_t *sc;
65
66 sc = device_get_softc(arg);
67 (void) pdq_interrupt(sc->sc_pdq);
68}
69
70/*
71 * This is the PCI configuration support.
72 */
73static int
74pdq_pci_probe(device_t dev)
75{
76 if (pci_get_vendor(dev) == DEC_VENDORID &&
77 pci_get_device(dev) == DEFPA_CHIPID) {
78 device_set_desc(dev, "Digital DEFPA PCI FDDI Controller");
79 return 0;
80 }
81 return ENXIO;
82}
83
84static int
85pdq_pci_attach(device_t dev)
86{
87 pdq_softc_t *sc;
88 int data;
89 struct resource *memres, *irqres;
90 int rid;
91 void *ih;
92
93 memres = NULL;
94 irqres = NULL;
95 sc = device_get_softc(dev);
96
97 data = pci_read_config(dev, PCIR_LATTIMER, 1);
98 if (data < DEFPA_LATENCY) {
99 data = DEFPA_LATENCY;
100 pci_write_config(dev, PCIR_LATTIMER, data, 1);
101 }
102
103 rid = PCI_CBMA;
104 memres = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0, ~0, 1, RF_ACTIVE);
105 if (!memres)
106 goto bad;
107
108 sc->sc_if.if_name = "fpa";
109 sc->sc_if.if_unit = device_get_unit(dev);
110 sc->sc_membase = (pdq_bus_memaddr_t) rman_get_virtual(memres);
111 sc->sc_pdq = pdq_initialize(PDQ_BUS_PCI, sc->sc_membase,
112 sc->sc_if.if_name, sc->sc_if.if_unit,
113 (void *) sc, PDQ_DEFPA);
114 if (sc->sc_pdq == NULL)
115 goto bad;
116 bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
117 pdq_ifattach(sc, NULL);
118 rid = 0;
119 irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
120 RF_SHAREABLE | RF_ACTIVE);
121 if (!irqres)
122 goto bad;
123 if (bus_setup_intr(dev, irqres, INTR_TYPE_NET, pdq_pci_ifintr,
124 (void *)dev, &ih))
125 goto bad;
126 return 0;
127
128bad:
129 if (memres)
130 bus_release_resource(dev, SYS_RES_MEMORY, PCI_CBMA, memres);
131 if (irqres)
132 bus_release_resource(dev, SYS_RES_IRQ, 0, irqres);
133 return ENXIO;
134}
135
136static void
137pdq_pci_shutdown(device_t dev)
138{
139 pdq_softc_t *sc;
140
141 sc = device_get_softc(dev);
142 pdq_hwreset(sc->sc_pdq);
143}
144
145static device_method_t pdq_pci_methods[] = {
146 /* Device interface */
147 DEVMETHOD(device_probe, pdq_pci_probe),
148 DEVMETHOD(device_attach, pdq_pci_attach),
149 DEVMETHOD(device_shutdown, pdq_pci_shutdown),
150 { 0, 0 }
151};
152static driver_t pdq_pci_driver = {
153 "fpa",
154 pdq_pci_methods,
155 sizeof(pdq_softc_t),
156};
157static devclass_t pdq_devclass;
158DRIVER_MODULE(if_fpa, pci, pdq_pci_driver, pdq_devclass, 0, 0);