Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[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.2 2003/06/17 04:28:33 dillon 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
40 #include <machine/bus.h>
41 #include <machine/resource.h>
42 #include <sys/rman.h>
43
44 #include <net/if.h>
45 #include <net/if_arp.h>
46
47 #include <dev/eisa/eisaconf.h>
48
49 #include <dev/vx/if_vxreg.h>
50
51 #define EISA_DEVICE_ID_3COM_3C592       0x506d5920
52 #define EISA_DEVICE_ID_3COM_3C597_TX    0x506d5970
53 #define EISA_DEVICE_ID_3COM_3C597_T4    0x506d5971
54 #define EISA_DEVICE_ID_3COM_3C597_MII   0x506d5972
55
56
57 #define VX_EISA_SLOT_OFFSET             0x0c80
58 #define VX_EISA_IOSIZE                  0x000a
59 #define VX_RESOURCE_CONFIG              0x0008
60
61
62 static const char *vx_match __P((eisa_id_t type));
63
64 static const char*
65 vx_match(eisa_id_t type)
66 {
67     switch (type) {
68       case EISA_DEVICE_ID_3COM_3C592:
69         return "3Com 3C592 Network Adapter";
70         break;
71       case EISA_DEVICE_ID_3COM_3C597_TX:
72         return "3Com 3C597-TX Network Adapter";
73         break;
74       case EISA_DEVICE_ID_3COM_3C597_T4:
75         return "3Com 3C597-T4 Network Adapter";
76         break;
77       case EISA_DEVICE_ID_3COM_3C597_MII:
78         return "3Com 3C597-MII Network Adapter";
79         break;
80       default:
81         break;
82     }
83     return (NULL);
84 }
85
86 static int
87 vx_eisa_probe(device_t dev)
88 {
89     const char     *desc;
90     u_long          iobase;
91     u_long          port;
92
93     desc = vx_match(eisa_get_id(dev));
94     if (!desc)
95         return (ENXIO);
96     device_set_desc(dev, desc);
97
98     port = eisa_get_slot(dev) * EISA_SLOT_SIZE;
99     iobase = port + VX_EISA_SLOT_OFFSET;
100
101     eisa_add_iospace(dev, iobase, VX_EISA_IOSIZE, RESVADDR_NONE);
102     eisa_add_iospace(dev, port, VX_IOSIZE, RESVADDR_NONE);
103
104     /* Set irq */
105     eisa_add_intr(dev, inw(iobase + VX_RESOURCE_CONFIG) >> 12,
106                   EISA_TRIGGER_EDGE);
107
108     return (0);
109 }
110
111 static int
112 vx_eisa_attach(device_t dev)
113 {
114     struct vx_softc *sc;
115     int             unit = device_get_unit(dev);
116     struct resource *io = 0;
117     struct resource *eisa_io = 0;
118     struct resource *irq = 0;
119     int             rid;
120     void            *ih;
121
122     /*
123      * The addresses are sorted in increasing order
124      * so we know the port to pass to the core ep
125      * driver comes first.
126      */
127     rid = 0;
128     io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
129                             0, ~0, 1, RF_ACTIVE);
130     if (!io) {
131         device_printf(dev, "No I/O space?!\n");
132         goto bad;
133     }
134
135     rid = 1;
136     eisa_io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
137                                  0, ~0, 1, RF_ACTIVE);
138     if (!eisa_io) {
139         device_printf(dev, "No I/O space?!\n");
140         goto bad;
141     }
142
143     if ((sc = vxalloc(unit)) == NULL)
144         goto bad;
145
146     sc->vx_io_addr = rman_get_start(io);
147
148     rid = 0;
149     irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
150                              0, ~0, 1, RF_ACTIVE);
151     if (!irq) {
152         device_printf(dev, "No irq?!\n");
153         vxfree(sc);
154         goto bad;
155     }
156
157     /* Now the registers are availible through the lower ioport */
158
159     vxattach(sc);
160
161     if (bus_setup_intr(dev, irq, INTR_TYPE_NET, vxintr, sc, &ih)) {
162         vxfree(sc);
163         goto bad;
164     }
165
166     return 0;
167
168  bad:
169     if (io)
170         bus_release_resource(dev, SYS_RES_IOPORT, 0, io);
171     if (eisa_io)
172         bus_release_resource(dev, SYS_RES_IOPORT, 0, eisa_io);
173     if (irq)
174         bus_release_resource(dev, SYS_RES_IRQ, 0, irq);
175     return -1;
176 }
177
178 static device_method_t vx_eisa_methods[] = {
179         /* Device interface */
180         DEVMETHOD(device_probe,         vx_eisa_probe),
181         DEVMETHOD(device_attach,        vx_eisa_attach),
182
183         { 0, 0 }
184 };
185
186 static driver_t vx_eisa_driver = {
187         "vx",
188         vx_eisa_methods,
189         1,                      /* unused */
190 };
191
192 static devclass_t vx_devclass;
193
194 DRIVER_MODULE(vx, eisa, vx_eisa_driver, vx_devclass, 0, 0);