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