Remove redundant settings. These are the same in /etc/defaults/rc.conf.
[dragonfly.git] / sys / dev / netif / vx / if_vx_eisa.c
1 /*
2  * Copyright (C) 1996 Naoki Hamada <nao@tom-yam.or.jp>
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. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the author nor the names of any co-contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD: src/sys/dev/vx/if_vx_eisa.c,v 1.14 2000/01/29 14:50:31 peter Exp $
30  * $DragonFly: src/sys/dev/netif/vx/if_vx_eisa.c,v 1.17 2008/08/17 04:32:35 sephe Exp $
31  */
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/socket.h>
37 #include <sys/module.h>
38 #include <sys/bus.h>
39 #include <sys/rman.h>
40 #include <sys/interrupt.h>
41
42 #include <net/if.h>
43 #include <net/if_arp.h>
44
45 #include <bus/eisa/eisaconf.h>
46
47 #include "if_vxreg.h"
48
49 #define EISA_DEVICE_ID_3COM_3C592       0x506d5920
50 #define EISA_DEVICE_ID_3COM_3C597_TX    0x506d5970
51 #define EISA_DEVICE_ID_3COM_3C597_T4    0x506d5971
52 #define EISA_DEVICE_ID_3COM_3C597_MII   0x506d5972
53
54
55 #define VX_EISA_SLOT_OFFSET             0x0c80
56 #define VX_EISA_IOSIZE                  0x000a
57 #define VX_RESOURCE_CONFIG              0x0008
58
59
60 static const char *vx_match (eisa_id_t type);
61
62 static const char*
63 vx_match(eisa_id_t type)
64 {
65     switch (type) {
66       case EISA_DEVICE_ID_3COM_3C592:
67         return "3Com 3C592 Network Adapter";
68       case EISA_DEVICE_ID_3COM_3C597_TX:
69         return "3Com 3C597-TX Network Adapter";
70       case EISA_DEVICE_ID_3COM_3C597_T4:
71         return "3Com 3C597-T4 Network Adapter";
72       case EISA_DEVICE_ID_3COM_3C597_MII:
73         return "3Com 3C597-MII Network Adapter";
74       default:
75         return (NULL);
76     }
77 }
78
79 static int
80 vx_eisa_probe(device_t dev)
81 {
82     const char     *desc;
83     u_long          iobase;
84     u_long          port;
85
86     desc = vx_match(eisa_get_id(dev));
87     if (!desc)
88         return (ENXIO);
89     device_set_desc(dev, desc);
90
91     port = eisa_get_slot(dev) * EISA_SLOT_SIZE;
92     iobase = port + VX_EISA_SLOT_OFFSET;
93
94     eisa_add_iospace(dev, iobase, VX_EISA_IOSIZE, RESVADDR_NONE);
95     eisa_add_iospace(dev, port, VX_IOSIZE, RESVADDR_NONE);
96
97     /* Set irq */
98     eisa_add_intr(dev, inw(iobase + VX_RESOURCE_CONFIG) >> 12,
99                   EISA_TRIGGER_EDGE);
100
101     return (0);
102 }
103
104 static int
105 vx_eisa_attach(device_t dev)
106 {
107     struct vx_softc *sc = device_get_softc(dev);
108     struct ifnet *ifp = &sc->arpcom.ac_if;
109     struct resource *eisa_io = NULL;
110     int             rid;
111
112     /*
113      * The addresses are sorted in increasing order
114      * so we know the port to pass to the core ep
115      * driver comes first.
116      */
117     rid = 0;
118     sc->vx_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
119     if (sc->vx_res == NULL) {
120         device_printf(dev, "No I/O space?!\n");
121         goto bad;
122     }
123
124     rid = 1;
125     eisa_io = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
126     if (eisa_io == NULL) {
127         device_printf(dev, "No I/O space?!\n");
128         goto bad;
129     }
130
131     sc->vx_bhandle = rman_get_bushandle(sc->vx_res);
132     sc->vx_btag = rman_get_bustag(sc->vx_res);
133
134     rid = 0;
135     sc->vx_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
136     if (sc->vx_irq == NULL) {
137         device_printf(dev, "No irq?!\n");
138         goto bad;
139     }
140
141     /* Now the registers are availible through the lower ioport */
142
143     vxattach(dev);
144
145     if (bus_setup_intr(dev, sc->vx_irq, INTR_MPSAFE, 
146                        vxintr, sc, &sc->vx_intrhand,
147                        ifp->if_serializer)
148     ) {
149         ether_ifdetach(&sc->arpcom.ac_if);
150         goto bad;
151     }
152
153     ifp->if_cpuid = ithread_cpuid(rman_get_start(sc->vx_irq));
154     KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus);
155
156     return 0;
157
158  bad:
159     if (sc->vx_res)
160         bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->vx_res);
161     if (eisa_io)
162         bus_release_resource(dev, SYS_RES_IOPORT, 0, eisa_io);
163     if (sc->vx_irq)
164         bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vx_irq);
165     return -1;
166 }
167
168 static device_method_t vx_eisa_methods[] = {
169         /* Device interface */
170         DEVMETHOD(device_probe,         vx_eisa_probe),
171         DEVMETHOD(device_attach,        vx_eisa_attach),
172
173         { 0, 0 }
174 };
175
176 static driver_t vx_eisa_driver = {
177         "vx",
178         vx_eisa_methods,
179         sizeof(struct vx_softc)
180 };
181
182 static devclass_t vx_devclass;
183
184 DRIVER_MODULE(if_vx, eisa, vx_eisa_driver, vx_devclass, 0, 0);