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